I can no longer use startActivity using any Intent, even Settings.ACTION_DISPLAY_SETTINGS, because it simply causes the app to crash.
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: Exception in native call
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.DISPLAY_SETTINGS pkg="myPackageName" }
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2239)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1878)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at android.app.Activity.startActivityForResult(Activity.java:5589)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:753)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at android.app.Activity.startActivityForResult(Activity.java:5547)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:734)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at android.app.Activity.startActivity(Activity.java:6045)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at android.app.Activity.startActivity(Activity.java:6012)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at myPackageName.SystemInfo.goToDisplayOptions(SystemInfo.java:149)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at java.lang.reflect.Method.invoke(Native Method)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:146)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at com.facebook.jni.NativeRunnable.run(Native Method)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at android.os.Handler.handleCallback(Handler.java:958)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at android.os.Looper.loopOnce(Looper.java:205)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at android.os.Looper.loop(Looper.java:294)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:233)
08-06 18:41:05.762 20049 20374 E unknown:ReactNative: at java.lang.Thread.run(Thread.java:1012)
I replaced my package name with "myPackageName" for posting here.
It worked before but after the upgrade to Android 14 and React Native 0.74.4, it is no longer working.
I already searched for days for the cause, but I am not seeing any issues causing this behaviour.
Intent i = new Intent();
i.setPackage(reactContext.getPackageName());
i.setAction(Settings.ACTION_DISPLAY_SETTINGS);
Objects.requireNonNull(reactContext.getCurrentActivity()).startActivity(i);
2
Answers
Hi please try removing the package name and try to check with below code :
No need to specify package name in system setting I think.
Part 1 :
This happens because if you explicitly define the package name of the intent to your application’s package then the intent can only be resolved by components within your application; this does not include the system settings activities.
Part 2 :
Here’s the correct way to create and start the intent to open the display settings:
Part 3 :
Safe implementation :