当我这样做时我的应用程序崩溃了:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Settings.System.canWrite(ListOfTerminalsActivity.this)) {
// Do stuff here
} else {
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
它发生在 ZUK Z2 的 API 23 上,这是日志;
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.action.MANAGE_WRITE_SETTINGS dat=package:pl.teminalmobile flg=0x10000000 }
01-24 12:33:56.123 30159 30159 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2464)
01-24 12:33:56.123 30159 30159 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2536)
01-24 12:33:56.123 30159 30159 E AndroidRuntime: at android.app.ActivityThread.access$900(ActivityThread.java:159)
01-24 12:33:56.123 30159 30159 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
01-24 12:33:56.123 30159 30159 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
01-24 12:33:56.123 30159 30159 E AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
01-24 12:33:56.123 30159 30159 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5504)
01-24 12:33:56.123 30159 30159 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
01-24 12:33:56.123 30159 30159 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
01-24 12:33:56.123 30159 30159 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-24 12:33:56.123 30159 30159 E AndroidRuntime: Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.action.MANAGE_WRITE_SETTINGS
这并没有发生,我的应用程序也没有崩溃,例如在设备 samsung s5 API 23、samsung s7 API 24 上
最佳答案
引用 the documentation for ACTION_MANAGE_WRITE_SETTINGS
:
In some cases, a matching Activity may not exist, so ensure you safeguard against this.
因此,将您的 startActivity()
调用包装在 try
/catch
block 中,如果您收到 ActivityNotFoundException
,做点别的。例如,您可以尝试相同的 Intent
操作但不包括 package
Uri
。
关于java - 找不到处理 Intent {act=android.settings.action.MANAGE_WRITE_SETTINGS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48422080/