gpt4 book ai didi

Android:java.lang.SecurityException:权限拒绝:启动 Intent

转载 作者:IT老高 更新时间:2023-10-28 13:02:07 25 4
gpt4 key购买 nike

我创建了一个包含 GWVectraNotifier Activity 的应用程序,该 Activity 被其他应用程序调用以显示通知。

在通知对话框中,会有“显示”按钮和“关闭”按钮。

点击“显示”按钮,会启动相应的 Activity 。

要检查上述应用程序的功能,

我在检查邮件事件触发器上从 K9Mail 应用程序启动了 GWVectraNotifier Activity 。

我能够成功启动 GWVectraNotifier Activity ,但单击“显示”按钮我将不得不启动 K9mail 的“消息列表” Activity 。为此,我编写了以下代码:

Intent i = new Intent();
i.setComponent(new ComponentName("com.fsck.k9", "com.fsck.k9.activity.MessageList"));
i.putExtra("account", accUuid);
i.putExtra("folder", accFolder);
startActivity(i);

抛出:

WARN/ActivityManager(59): Permission denied: checkComponentPermission() reqUid=10050
WARN/ActivityManager(59): Permission Denial: starting Intent { cmp=com.fsck.k9/.activity.MessageList (has extras) } from ProcessRecord{43f6d7c8 675:com.i10n.notifier/10052} (pid=675, uid=10052) requires null
WARN/System.err(675): java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.fsck.k9/.activity.MessageList (has extras) } from ProcessRecord{43f6d7c8 675:com.i10n.notifier/10052} (pid=675, uid=10052) requires null
WARN/System.err(675): at android.os.Parcel.readException(Parcel.java:1247)
WARN/System.err(675): at android.os.Parcel.readException(Parcel.java:1235)
WARN/System.err(675): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)
WARN/System.err(675): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
WARN/System.err(675): at android.app.Activity.startActivityForResult(Activity.java:2817)
WARN/System.err(675): at android.app.Activity.startActivity(Activity.java:2923)
WARN/System.err(675): at com.i10n.notifier.GWVectraNotifier$2$1.run(GWVectraNotifier.java:63)
WARN/System.err(675): at android.app.Activity.runOnUiThread(Activity.java:3707)
WARN/System.err(675): at com.i10n.notifier.GWVectraNotifier$2.onClick(GWVectraNotifier.java:53)
WARN/System.err(675): at android.view.View.performClick(View.java:2408)
WARN/System.err(675): at android.view.View$PerformClick.run(View.java:8816)
WARN/System.err(675): at android.os.Handler.handleCallback(Handler.java:587)
WARN/System.err(675): at android.os.Handler.dispatchMessage(Handler.java:92)
WARN/System.err(675): at android.os.Looper.loop(Looper.java:123)
WARN/System.err(675): at android.app.ActivityThread.main(ActivityThread.java:4627)
WARN/System.err(675): at java.lang.reflect.Method.invokeNative(Native Method)
WARN/System.err(675): at java.lang.reflect.Method.invoke(Method.java:521)
WARN/System.err(675): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
WARN/System.err(675): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
WARN/System.err(675): at dalvik.system.NativeStart.main(Native Method)

实际上,我无法理解在通知程序应用程序的 list 文件中包含哪些权限来访问 k9Mail 的 MessageList。我粘贴在 k9mail 应用程序 list 文件中包含的权限下方:

<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.READ_OWNER_DATA"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="org.thialfihar.android.apg.permission.READ_KEY_DETAILS"/>
<permission android:name="com.fsck.k9.permission.READ_ATTACHMENT"
android:permissionGroup="android.permission-group.MESSAGES"
android:protectionLevel="dangerous"
android:label="@string/read_attachment_label"
android:description="@string/read_attachment_desc"/>
<uses-permission android:name="com.fsck.k9.permission.READ_ATTACHMENT"/>
<permission android:name="com.fsck.k9.permission.REMOTE_CONTROL"
android:permissionGroup="android.permission-group.MESSAGES"
android:protectionLevel="dangerous"
android:label="@string/remote_control_label"
android:description="@string/remote_control_desc"/>
<uses-permission android:name="com.fsck.k9.permission.REMOTE_CONTROL"/>
<permission android:name="com.fsck.k9.permission.READ_MESSAGES"
android:permissionGroup="android.permission-group.MESSAGES"
android:protectionLevel="normal"
android:label="@string/read_messages_label"
android:description="@string/read_messages_desc"/>
<uses-permission android:name="com.fsck.k9.permission.READ_MESSAGES"/>
<permission android:name="com.fsck.k9.permission.DELETE_MESSAGES"
android:permissionGroup="android.permission-group.MESSAGES"
android:protectionLevel="normal"
android:label="@string/delete_messages_label"
android:description="@string/read_messages_desc"/>
<uses-permission android:name="com.fsck.k9.permission.DELETE_MESSAGES"/>

谁能告诉我在我的应用中包含哪些权限?在上面的权限中,有些权限只适用于 k9mail ,因为那些是为 k9 编写的权限类。所以,我只能在上面给定的权限中包含android的内置权限。我也尝试过这样做,但它并没有解决我的问题:(

最佳答案

您必须在您尝试启动的 Activity 的 list 文件中添加 android:exported="true"

来自 android:exported documentation :

android:exported
Whether or not the activity can be launched by components of other applications — "true" if it can be, and "false" if not. If "false", the activity can be launched only by components of the same application or applications with the same user ID.

The default value depends on whether the activity contains intent filters. The absence of any filters means that the activity can be invoked only by specifying its exact class name. This implies that the activity is intended only for application-internal use (since others would not know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the activity is intended for external use, so the default value is "true".

This attribute is not the only way to limit an activity's exposure to other applications. You can also use a permission to limit the external entities that can invoke the activity (see the permission attribute).

关于Android:java.lang.SecurityException:权限拒绝:启动 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4162447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com