gpt4 book ai didi

java - 对外部 Activity 的 Intent 拒绝许可

转载 作者:行者123 更新时间:2023-11-30 04:48:50 31 4
gpt4 key购买 nike

我的整个想法有点复杂,但只是为了将事情分解,使它们简单明了……我在一个小部件上有一个按钮,我需要用它打开官方 Facebook 应用。

这是我使用的代码:

 Intent PlacesIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("com.facebook.katana", "com.facebook.katana.activity.places.PlacesNearbyActivity"));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, PlacesIntent, 0);
views.setOnClickPendingIntent(R.id.places, pendingIntent);

我在 logcat 中收到此错误:

 11-06 22:26:48.117: WARN/ActivityManager(85): Permission denied: checkComponentPermission() reqUid=10055
11-06 22:26:48.117: WARN/ActivityManager(85): Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.facebook.katana/.activity.places.PlacesNearbyActivity bnds=[371,129][428,203] } from null (pid=-1, uid=10157) requires null
11-06 22:26:48.127: WARN/ActivityManager(85): Unable to send startActivity intent
11-06 22:26:48.127: WARN/ActivityManager(85): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.facebook.katana/.activity.places.PlacesNearbyActivity bnds=[371,129][428,203] } from null (pid=-1, uid=10157) requires null
11-06 22:26:48.127: WARN/ActivityManager(85): at com.android.server.am.ActivityManagerService.startActivityLocked(ActivityManagerService.java:3223)
11-06 22:26:48.127: WARN/ActivityManager(85): at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:3980)
11-06 22:26:48.127: WARN/ActivityManager(85): at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:212)
11-06 22:26:48.127: WARN/ActivityManager(85): at com.android.server.am.ActivityManagerService.startActivityIntentSender(ActivityManagerService.java:3843)
11-06 22:26:48.127: WARN/ActivityManager(85): at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:210)
11-06 22:26:48.127: WARN/ActivityManager(85): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1480)
11-06 22:26:48.127: WARN/ActivityManager(85): at android.os.Binder.execTransact(Binder.java:288)
11-06 22:26:48.127: WARN/ActivityManager(85): at dalvik.system.NativeStart.run(Native Method)

如果我使用,

Intent PlacesIntent1 = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("com.facebook.katana", "com.facebook.katana.HomeActivity"));
PendingIntent pendingIntent1 = PendingIntent.getActivity(context, 0, PlacesIntent1, 0);
views.setOnClickPendingIntent(R.id.facebook, pendingIntent1);

一切都很好,它打开了家庭 Activity ,但这并不是我真正想要做的。

我试过了

com.facebook.katana.activity.places.PlacesNearbyActivity - I actually see a respons in the logcat about the denail with this one
com.facebook.katana.activity.PlacesNearbyActivity
com.facebook.katana.places.PlacesNearbyActivity
com.facebook.katana.PlacesNearbyActivity

其他人什么都没发生

这是我在手机上手动打开 Activity 时在 logcat 中看到的内容:

11-06 20:20:38.295: INFO/ActivityManager(85): Starting activity: Intent { cmp=com.facebook.katana/.activity.places.PlacesNearbyActivity }

11-06 22:03:28.027: INFO/ActivityManager(85): Starting activity: Intent { flg=0x4000000 cmp=com.facebook.katana/.HomeActivity }

那么,这让您大概了解我是如何获得我的信息的。

最佳答案

我不同意 CommonsWare 的回答。答案也根本没有被接受,虽然我认为答案是正确的一次,然后我尝试了以下代码并发现您可以使用以下代码从另一个应用程序打开 place Activity ...

appAction = Intent.ACTION_VIEW;
appPackage = "com.facebook.katana";
appActivity = "com.facebook.katana.IntentUriHandler";

data = Uri.parse("facebook:/places").buildUpon().appendQueryParameter("user", Long.toString(post.getSourceId())).appendQueryParameter("post", post.getPostId()).build();

Intent intent = new Intent(appAction);
intent.setClassName(appPackage, appActivity);

intent.setData(data);
ctx.startActivity(intent);

关于java - 对外部 Activity 的 Intent 拒绝许可,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4116273/

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