AndroidRuntime: java.lang.SecurityException: Permission Denial

本文介绍了解决在Android中跨进程启动Activity时遇到的安全异常问题。通过调整目标Activity的exported属性为true,可以成功解决由权限不足导致的启动失败问题。


在android调用另一个进程中的activity时,发生下面的错误:

E AndroidRuntime: java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.mediatek.op01.plugin/com.mediatek.phone.callforward.CallForwardTimeActivity (has extras) } from ProcessRecord{2e4925ca 6339:com.android.phone/1001} (pid=6339, uid=1001) not exported from uid 1000


intent跳转时发现没有权限引起的:

         Intent intent = new Intent(mPluginContext, CallForwardTimeActivity.class);
         mActivity.startActivityForResult(intent, SET_TIME_REQUEST);


经查看发现将exported属性变为true即可:

        <activity android:name="com.mediatek.phone.callforward.CallForwardTimeActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:launchMode="singleTop"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

06-05 06:24:05.669 5900 5900 D AndroidRuntime: Shutting down VM 06-05 06:24:05.672 5900 5900 E AndroidRuntime: FATAL EXCEPTION: main 06-05 06:24:05.672 5900 5900 E AndroidRuntime: Process: com.avatr.cockpit.settings, PID: 5900 06-05 06:24:05.672 5900 5900 E AndroidRuntime: java.lang.RuntimeException: Unable to create application com.avatr.cockpit.settings.CockpitSettingsApplication: java.lang.SecurityException: Permission Denial: Component com.avatr.cockpit.settings/.service.SettingsService requests FLAG_SINGLE_USER, but app does not hold android.permission.INTERACT_ACROSS_USERS 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7107) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2305) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:218) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.os.Looper.loop(Looper.java:307) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8309) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:573) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: Caused by: java.lang.SecurityException: Permission Denial: Component com.avatr.cockpit.settings/.service.SettingsService requests FLAG_SINGLE_USER, but app does not hold android.permission.INTERACT_ACROSS_USERS 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.os.Parcel.createExceptionOrNull(Parcel.java:3079) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.os.Parcel.createException(Parcel.java:3063) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:3046) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2988) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:6047) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1931) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.app.ContextImpl.startService(ContextImpl.java:1900) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.content.ContextWrapper.startService(ContextWrapper.java:825) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at com.avatr.cockpit.settings.CockpitSettingsApplication.onCreate(CockpitSettingsApplication.java:20) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1316) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7102) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: ... 9 more 06-05 06:24:05.672 5900 5900 E AndroidRuntime: Caused by: android.os.RemoteException: Remote stack trace: 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at com.android.server.am.ActivityManagerService.isSingleton(ActivityManagerService.java:13546) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at com.android.server.am.ActiveServices.retrieveServiceLocked(ActiveServices.java:4394) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:833) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at com.android.server.am.ActiveServices.startServiceLocked(ActiveServices.java:794) 06-05 06:24:05.672 5900 5900 E AndroidRuntime: at com.android.server.am.ActivityManagerService.startService(ActivityManagerService.java:13415) 06-05 06:24:05.672 5900 5900 E AndroidRuntime:
最新发布
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值