打开activity,报错java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.ac
程序员文章站
2022-06-15 09:36:25
问题Android9 机器,一个应用启动另一个应用// 启动代码如下Intent intent = new Intent(Intent.ACTION_MAIN); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setComponent(new ComponentName(pkg, actName)); intent.addCategory(In...
问题
Android9 机器,一个应用启动另一个应用
// 启动代码如下
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName(pkg, actName));
intent.addCategory(Intent.CATEGORY_LAUNCHER);
mContext.startActivity(intent);
// 被启动应用的AndroidManifest.xml
//非主Activity
<activity
android:name=".ui.activity.ActivityX"
android:launchMode="singleTask"
</activity>
报错
如下
03-27 09:31:05.648 W/ActivityManager( 1964): Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.exam/.ActivityX } from ProcessRecord{e9fd3c5 3260:com.../u0a36} (pid=3260, uid=10036) not exported from uid 1000
03-27 09:31:05.650 D/AndroidRuntime( 3260): Shutting down VM
03-27 09:31:05.660 E/AndroidRuntime( 3260): FATAL EXCEPTION: main
03-27 09:31:05.660 E/AndroidRuntime( 3260): Process: com.exam.androidA, PID: 3260
03-27 09:31:05.660 E/AndroidRuntime( 3260): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.exam/.ActivityX } from ProcessRecord{e9fd3c5 3260:com.exam.androidA/u0a36} (pid=3260, uid=10036) not exported from uid 1000
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.os.Parcel.createException(Parcel.java:1950)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.os.Parcel.readException(Parcel.java:1918)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.os.Parcel.readException(Parcel.java:1868)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:3755)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1669)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.app.ContextImpl.startActivity(ContextImpl.java:917)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.app.ContextImpl.startActivity(ContextImpl.java:888)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.content.ContextWrapper.startActivity(ContextWrapper.java:379)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.view.View.performClick(View.java:6597)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.view.View.performClickInternal(View.java:6574)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.view.View.access$3100(View.java:778)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.view.View$PerformClick.run(View.java:25885)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.os.Handler.handleCallback(Handler.java:873)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.os.Handler.dispatchMessage(Handler.java:99)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.os.Looper.loop(Looper.java:193)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at android.app.ActivityThread.main(ActivityThread.java:6671)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at java.lang.reflect.Method.invoke(Native Method)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:871)
03-27 09:31:05.660 E/AndroidRuntime( 3260): Caused by: android.os.RemoteException: Remote stack trace:
03-27 09:31:05.660 E/AndroidRuntime( 3260): at com.android.server.am.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1781)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at com.android.server.am.ActivityStarter.startActivity(ActivityStarter.java:717)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at com.android.server.am.ActivityStarter.startActivity(ActivityStarter.java:544)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:1099)
03-27 09:31:05.660 E/AndroidRuntime( 3260): at com.android.server.am.ActivityStarter.execute(ActivityStarter.java:486)
03-27 09:31:05.660 E/AndroidRuntime( 3260):
03-27 09:31:05.668 W/ActivityManager( 1964): Force finishing activity com.exam.androidA
解决
此activity加入action属性
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
本文地址:https://blog.csdn.net/geniushorse/article/details/108582903
上一篇: APP自动化基础之环境准备