我正在尝试设置社交分享。当我选择共享时,通过显示所有可用选项,它工作正常。但是无论如何我可以检查用户是否选择“Facebook”作为他们共享的方法,因为我想在发生这种情况时触发相关的 facebok sdk 相关代码。与其他共享选项不同,如果我不采用他们的 SDK 路线,Facebook 似乎对可以发布的内容有限制。
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.social_share){
//working - this opens up available sharing options on device.
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "A Title");
i.putExtra(Intent.EXTRA_TEXT, "This is content... ");
startActivity(i.createChooser(i, "Share"));
//I want to use this code if facebook is selected.
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Hello Facebook")
.setContentDescription(
"The 'Hello Facebook' sample showcases simple Facebook integration")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
.setImageUrl(Uri.parse("http://....."))
shareDialog.show(linkContent);
}
}
return true;
}
最佳答案
没有直接的方法来识别使用 ACTION_SEND Intent 选择了哪个应用。您将需要编写一个自定义应用程序选择器对话框来确定用户选择哪一个。检查this post查看其他用户作为类似问题的答案所写的一些内容。
关于android - 确定用户是否选择 Facebook 作为社交分享选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34637801/