Permission Denial for intent to external activity

2019-04-15 06:07发布

问题:

My whole idea is a little more complex, but just to break things down so they're simple and to the point here...I have a button on a widget that i need to open the "places" activity in the official facebook app.

Here's the code i'm using:

 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);

I get this error in the 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)

If i use,

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);

Everything works great and it opens the home activity, but that's not really what i'm trying to do.

I've tried

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

and nothing happens with the others

Here's what i see in the logcat when manually opening the activities on my phone:

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 }

So, that gives you sort of an idea how i got my information.

回答1:

I have a button on a widget that i need to open the "places" activity in the official facebook app.

Since it appears that Facebook does not endorse integration with their Android application this way, please do not do this.

Permission denied: checkComponentPermission() reqUid=10055

That activity can only be started by Facebook.



回答2:

I disagree with Answer by CommonsWare. The answer is also not at all accepted, though I thought the answer is correct once, then I tried following code and found out that you can open place Activity from another app using following code...

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);