【发布时间】:2014-05-15 09:17:44
【问题描述】:
我已下载 Facebook SDK 并正确设置。一切都很完美。我可以毫无问题地分享链接或更新我的状态。现在我想做点别的。我想以这样的方式集成 Share Intent 和 Facebook SDK,当我在我的应用中单击分享按钮时,应该调用分享意图并显示应用列表。
现在,如果从列表中选择 Facebook,它应该会打开我在应用上应用的 Facebook SDK 共享方法,而无需共享意图。如果选择了任何其他应用程序(Gmail/Twitter/SMS 等),则共享意图应正常调用相应的意图。
到目前为止,我尝试了以下代码:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = "Here is the share content body";
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"http://somelink.com/somethingelse.php");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList =
pm.queryIntentActivities(sharingIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.name).contains("facebook")) {
Log.d("its here:", "goood");
FacebookDialog shareDialog =
new FacebookDialog.ShareDialogBuilder((Activity) v.getContext())
.setLink("http://somelink.com/somethingelse.php").build();
uiHelper.trackPendingDialogCall(shareDialog.present());
final ActivityInfo activity = app.activityInfo;
final ComponentName name =
new ComponentName(activity.applicationInfo.packageName, activity.name);
sharingIntent.addCategory(Intent.CATEGORY_LAUNCHER);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
sharingIntent.setComponent(name);
v.getContext().startActivity(sharingIntent);
break;
} else {
Log.d("shouldnt be here", "nooo");
startActivity(Intent.createChooser(sharingIntent, "Share via"));
break;
}
}
我试过这段代码,但没有运气。共享意图被调用,当我点击 Facebook 时,它会打开一个 Facebook 状态更新页面,我希望它调用我设置的 Facebook SDK 方法,并使用预定义的链接通过该方法运行。
我怎样才能做到这一点?
【问题讨论】:
标签: android facebook android-intent