Browse Source

[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 years ago
parent
commit
292f3ab1bd

+ 13
- 2
android/sdk/src/main/java/org/jitsi/meet/sdk/AndroidSettingsModule.java View File

5
 
5
 
6
 package org.jitsi.meet.sdk;
6
 package org.jitsi.meet.sdk;
7
 
7
 
8
+import android.content.ActivityNotFoundException;
8
 import android.content.Context;
9
 import android.content.Context;
9
 import android.content.Intent;
10
 import android.content.Intent;
10
 import android.net.Uri;
11
 import android.net.Uri;
11
 import android.provider.Settings;
12
 import android.provider.Settings;
12
 
13
 
14
+import com.facebook.react.bridge.Promise;
13
 import com.facebook.react.bridge.ReactApplicationContext;
15
 import com.facebook.react.bridge.ReactApplicationContext;
14
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
16
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
15
 import com.facebook.react.bridge.ReactMethod;
17
 import com.facebook.react.bridge.ReactMethod;
25
     }
27
     }
26
 
28
 
27
     @ReactMethod
29
     @ReactMethod
28
-    public void open() {
30
+    public void open(Promise promise) {
29
         Context context = getReactApplicationContext();
31
         Context context = getReactApplicationContext();
30
         Intent intent = new Intent();
32
         Intent intent = new Intent();
31
 
33
 
34
         intent.setData(
36
         intent.setData(
35
             Uri.fromParts("package", context.getPackageName(), null));
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 View File

80
 function _openSettings() {
80
 function _openSettings() {
81
     switch (Platform.OS) {
81
     switch (Platform.OS) {
82
     case 'android':
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
         break;
92
         break;
85
 
93
 
86
     case 'ios':
94
     case 'ios':

Loading…
Cancel
Save