你好有很多问题和答案availbe java.lang.SecurityException:权限拒绝我尝试所有答案但没有得到适当的解决方案,并且很少有设备发生此错误。
喜欢 HUAWEI Y6 Pro 操作系统 android Lollipop 5.0
这是我的代码调用Intent
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
startActivity(intent);
<uses-permission xmlns:tools="http://schemas.android.com/tools"
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions"/>
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".ui.activity.MainActivity"
android:label="@string/app_name"
android:exported="true"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
错误记录如下
Fatal Exception: java.lang.SecurityException: Permission Denial: starting Intent { act=android.settings.USAGE_ACCESS_SETTINGS cmp=com.android.settings/.Settings$UsageAccessSettingsActivity } from ProcessRecord{3e3e2f8a 13479:com.lj.applocker/u0a114} (pid=13479, uid=10114) 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:2528)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
at android.app.Activity.startActivityForResult(Activity.java:3849)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(Unknown Source)
at android.support.v4.app.FragmentActivity.startActivityForResult(Unknown Source)
at android.app.Activity.startActivityForResult(Activity.java:3791)
at android.support.v4.app.FragmentActivity.startActivityForResult(Unknown Source)
at com.lj.applocker.common.BaseActivity.startActivityForResult(Unknown Source)
at android.app.Activity.startActivity(Activity.java:4130)
at android.app.Activity.startActivity(Activity.java:4098)
at com.lj.applocker.common.BaseActivity.startActivity(Unknown Source)
at com.lj.applocker.ui.activity.MainActivity.callSetting(Unknown Source)
at com.lj.applocker.ui.activity.MainActivity.onNavigationItemSelected(Unknown Source)
at com.lj.applocker.ui.activity.MainActivity$1.onClick(Unknown Source)
at android.support.v7.app.AlertController$ButtonHandler.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5667)
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:962)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
任何帮助都将受到赞赏
由于
答案 0 :(得分:0)
您可以尝试在AndroidManifest.xml中设置权限声明。
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />