关于Android抛出java.lang.SecurityException: Permission Denial的错误

时间:2022-10-12 00:07:07

详细Log如下:

01-02 12:57:52.838: E/AndroidRuntime(3453): FATAL EXCEPTION: main
01-02 12:57:52.838: E/AndroidRuntime(3453): Process: com.malata.change, PID: 3453
01-02 12:57:52.838: E/AndroidRuntime(3453): java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.android.launcher3/.EffectsPreference } from ProcessRecord{41ff5fd8 3453:com.malata.change/u0a28} (pid=3453, uid=10028) not exported from uid 10052
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.os.Parcel.readException(Parcel.java:1465)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.os.Parcel.readException(Parcel.java:1419)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2173)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1425)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.app.Activity.startActivityForResult(Activity.java:3485)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.app.Activity.startActivityForResult(Activity.java:3446)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.app.Activity.startActivity(Activity.java:3688)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.app.Activity.startActivity(Activity.java:3656)
01-02 12:57:52.838: E/AndroidRuntime(3453): at com.malata.change.ChangeActivity.startEffectManager(ChangeActivity.java:153)
01-02 12:57:52.838: E/AndroidRuntime(3453): at com.malata.change.ChangeActivity.access$2(ChangeActivity.java:149)
01-02 12:57:52.838: E/AndroidRuntime(3453): at com.malata.change.ChangeActivity$GridDialog$1.onItemClick(ChangeActivity.java:125)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.widget.AdapterView.performItemClick(AdapterView.java:299)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.widget.AbsListView.performItemClick(AbsListView.java:1152)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3014)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.widget.AbsListView$3.run(AbsListView.java:3865)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.os.Handler.handleCallback(Handler.java:808)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.os.Handler.dispatchMessage(Handler.java:103)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.os.Looper.loop(Looper.java:193)
01-02 12:57:52.838: E/AndroidRuntime(3453): at android.app.ActivityThread.main(ActivityThread.java:5292)
01-02 12:57:52.838: E/AndroidRuntime(3453): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 12:57:52.838: E/AndroidRuntime(3453): at java.lang.reflect.Method.invoke(Method.java:515)
01-02 12:57:52.838: E/AndroidRuntime(3453): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
01-02 12:57:52.838: E/AndroidRuntime(3453): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
01-02 12:57:52.838: E/AndroidRuntime(3453): at dalvik.system.NativeStart.main(Native Method)


注意log中的第四行有个not exported from uid 10052,说明这个Activity只能在应用程序内部使用(因为通常外部应用程序是不会知道这个类名的,关于android:exported,可详见http://blog.csdn.net/fireofstar/article/details/7583047),所以外部应用程序无法访问或者(通过Intent)启动该Activity,需在AndroidManifest.xml中,为该Activity配置android:exported="true"即可,验证OK!


如果有什么错误,请大家指出,希望大家能共同学习,一起进步!感谢CSDN上的朋友们!