[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
pull/2379/head jitsi-meet_2746
Saúl Ibarra Corretgé 7 years ago committed by Paweł Domas
parent a3cb081609
commit 292f3ab1bd
  1. 15
      android/sdk/src/main/java/org/jitsi/meet/sdk/AndroidSettingsModule.java
  2. 10
      react/features/mobile/permissions/middleware.js

@ -5,11 +5,13 @@
package org.jitsi.meet.sdk; package org.jitsi.meet.sdk;
import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.provider.Settings; import android.provider.Settings;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReactMethod;
@ -25,7 +27,7 @@ class AndroidSettingsModule extends ReactContextBaseJavaModule {
} }
@ReactMethod @ReactMethod
public void open() { public void open(Promise promise) {
Context context = getReactApplicationContext(); Context context = getReactApplicationContext();
Intent intent = new Intent(); Intent intent = new Intent();
@ -34,6 +36,15 @@ class AndroidSettingsModule extends ReactContextBaseJavaModule {
intent.setData( intent.setData(
Uri.fromParts("package", context.getPackageName(), null)); Uri.fromParts("package", context.getPackageName(), null));
context.startActivity(intent); try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
// Some devices may give an error here.
// https://developer.android.com/reference/android/provider/Settings.html#ACTION_APPLICATION_DETAILS_SETTINGS
promise.reject(e);
return;
}
promise.resolve(null);
} }
} }

@ -80,7 +80,15 @@ function _alertPermissionErrorWithSettings(trackType) {
function _openSettings() { function _openSettings() {
switch (Platform.OS) { switch (Platform.OS) {
case 'android': case 'android':
NativeModules.AndroidSettings.open(); NativeModules.AndroidSettings.open().catch(() => {
Alert.alert(
'Error opening settings',
'Please open settings and grant the required permissions',
[
{ text: 'OK' }
]
);
});
break; break;
case 'ios': case 'ios':

Loading…
Cancel
Save