浏览代码

[Android] Fix crash if settings activity cannot be opened

The documentation states this is possible, so make sure we handle such errors.

Ref:
https://developer.android.com/reference/android/provider/Settings.html#ACTION_APPLICATION_DETAILS_SETTINGS
master
Saúl Ibarra Corretgé 7 年前
父节点
当前提交
292f3ab1bd

+ 13
- 2
android/sdk/src/main/java/org/jitsi/meet/sdk/AndroidSettingsModule.java 查看文件

@@ -5,11 +5,13 @@
5 5
 
6 6
 package org.jitsi.meet.sdk;
7 7
 
8
+import android.content.ActivityNotFoundException;
8 9
 import android.content.Context;
9 10
 import android.content.Intent;
10 11
 import android.net.Uri;
11 12
 import android.provider.Settings;
12 13
 
14
+import com.facebook.react.bridge.Promise;
13 15
 import com.facebook.react.bridge.ReactApplicationContext;
14 16
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
15 17
 import com.facebook.react.bridge.ReactMethod;
@@ -25,7 +27,7 @@ class AndroidSettingsModule extends ReactContextBaseJavaModule {
25 27
     }
26 28
 
27 29
     @ReactMethod
28
-    public void open() {
30
+    public void open(Promise promise) {
29 31
         Context context = getReactApplicationContext();
30 32
         Intent intent = new Intent();
31 33
 
@@ -34,6 +36,15 @@ class AndroidSettingsModule extends ReactContextBaseJavaModule {
34 36
         intent.setData(
35 37
             Uri.fromParts("package", context.getPackageName(), null));
36 38
 
37
-        context.startActivity(intent);
39
+        try {
40
+            context.startActivity(intent);
41
+        } catch (ActivityNotFoundException e) {
42
+            // Some devices may give an error here.
43
+            // https://developer.android.com/reference/android/provider/Settings.html#ACTION_APPLICATION_DETAILS_SETTINGS
44
+            promise.reject(e);
45
+            return;
46
+        }
47
+
48
+        promise.resolve(null);
38 49
     }
39 50
 }

+ 9
- 1
react/features/mobile/permissions/middleware.js 查看文件

@@ -80,7 +80,15 @@ function _alertPermissionErrorWithSettings(trackType) {
80 80
 function _openSettings() {
81 81
     switch (Platform.OS) {
82 82
     case 'android':
83
-        NativeModules.AndroidSettings.open();
83
+        NativeModules.AndroidSettings.open().catch(() => {
84
+            Alert.alert(
85
+                'Error opening settings',
86
+                'Please open settings and grant the required permissions',
87
+                [
88
+                    { text: 'OK' }
89
+                ]
90
+            );
91
+        });
84 92
         break;
85 93
 
86 94
     case 'ios':

正在加载...
取消
保存