1

I get java.lang.SecurityException when try to startActivityForResult(intent, requestCode); with final Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS); intent. Interesting that this crash happens only on Huawei with Android 5.1 - 5.1.1 I haven't Huawei device. Could you please give me advice what it can be.

Stacktrace

Fatal Exception: java.lang.SecurityException: Permission Denial: starting Intent { act=android.settings.USAGE_ACCESS_SETTINGS cmp=com.android.settings/.Settings$UsageAccessSettingsActivity } from ProcessRecord{11b5f1a1 19764:com.myproject.my/u0a167} (pid=19764, uid=10167) not exported from uid 1000
       at android.os.Parcel.readException(Parcel.java:1546)
       at android.os.Parcel.readException(Parcel.java:1499)
       at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2448)
       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1496)
       at android.app.Activity.startActivityForResult(Activity.java:3794)
       at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
       at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:77)
       at android.app.Activity.startActivityForResult(Activity.java:3755)
       at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
       at com.myproject.my.utils.PermissionsHelper$2.onClick(PermissionsHelper.java:134)
       at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:157)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5298)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:911)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)
4

2 回答 2

6

For whatever reason, Huawei left the <intent-filter> in place for this activity, but they marked it as not exported. There is no way that you can start the activity. All you can do is catch the exception and explain to the user that you cannot navigate there.

于 2017-04-10T12:46:39.933 回答
0

According to android developer documentation.

In some cases, a matching Activity may not exist, so ensure you safeguard against this.

Link : ACTION_USAGE_ACCESS_SETTINGS

于 2017-04-10T12:49:59.973 回答