我无法再使用任何 Intent 来使用 startActivity,甚至是 Settings.ACTION_DISPLAY_SETTINGS,因为它只会导致应用程序崩溃。
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)
我将我的包名称替换为“myPackageName”以便在此处发布。
之前可以用,但升级到 Android 14 和 React Native 0.74.4 后,就不再用了。
我已经搜索了几天的原因,但我没有看到任何导致此行为的问题。
Intent i = new Intent();
i.setPackage(reactContext.getPackageName());
i.setAction(Settings.ACTION_DISPLAY_SETTINGS);
reactContext.getCurrentActivity().startActivity(i);
您好,请尝试删除包名称并尝试使用以下代码进行检查
Intent i = new Intent(Settings.ACTION_DISPLAY_SETTINGS);
reactContext.getCurrentActivity().startActivity(i);
我认为不需要在系统设置中指定包名称。