Cannot find handle intent {act=android.settings.action.MANAGE_WRITE_SETTINGS… here is a solution to the problem.
Cannot find handle intent {act=android.settings.action.MANAGE_WRITE_SETTINGS
My app crashes when I do this :
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);
}
}
It happens on API 23 of ZUK Z2, here are the logs;
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
This did not
happen and my application did not crash, for example on devices Samsung s5 API 23, Samsung s7 API 24
Solution
Quote the documentation for ACTION_MANAGE_WRITE_SETTINGS
:
In some cases, a matching Activity may not exist, so ensure you safeguard against this.
So wrap your startActivity()
call in a try
/catch
block, and if you receive an ActivityNotFoundException
, do something else. For example, you can try the same intent
action but not include the package
URI
.