Android and Facebook share intent

前端 未结 12 2235
闹比i
闹比i 2020-11-22 13:02

I\'m developing an Android app and am interested to know how you can update the app user\'s status from within the app using Android\'s share intents.

Having looked

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 13:49

    This solution works aswell. If there is no Facebook installed, it just runs the normal share-dialog. If there is and you are not logged in, it goes to the login screen. If you are logged in, it will open the share dialog and put in the "Share url" from the Intent Extra.

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, "Share url");
    intent.setType("text/plain");
    
    List matches = getMainFragmentActivity().getPackageManager().queryIntentActivities(intent, 0);
    for (ResolveInfo info : matches) {
        if (info.activityInfo.packageName.toLowerCase().contains("facebook")) {
            intent.setPackage(info.activityInfo.packageName);
        }
    }
    
    startActivity(intent);
    

提交回复
热议问题