Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Activity found to handle Intent { act=android.settings.action.MANAGE_WRITE_SETTINGS

Tags:

java

android

My application crash 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 happend on API 23 in ZUK Z2 this is 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

It doesn't happend and my application not crash for example on device samsung s5 API 23, samsung s7 API 24

like image 461
Krzysztof Pokrywka Avatar asked Jan 24 '18 12:01

Krzysztof Pokrywka


1 Answers

Quoting 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 get an ActivityNotFoundException, do something else. For example, you could try the same Intent action but not include the package Uri.

like image 55
CommonsWare Avatar answered Sep 30 '22 17:09

CommonsWare