由于几天通过意图向facebook messenger发送文本不起作用,我尝试了几种方法: 第一:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.messenger_text));
sendIntent.setType("text/plain");
sendIntent.setPackage("com.facebook.orca");
秒(基于facebook docs):
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.facebook.orca");
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_STREAM, getString(R.string.messenger_text));
intent.putExtra(EXTRA_PROTOCOL_VERSION, PROTOCOL_VERSION);
intent.putExtra(EXTRA_APP_ID, YOUR_APP_ID);
有人有工作的例子吗?我认为这是一个新的问题,以及最后的facebook messenger api更新。
答案 0 :(得分:3)
这对我有用:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "My message to send");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.facebook.orca");
try {
startActivity(sendIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.show(this, "Please Install Facebook Messenger");
}
答案 1 :(得分:1)
以下是使用新API的工作解决方案:
if (MessageDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("TITLE")
.setContentDescription("Desc")
.setContentUrl(Uri.parse("http://url"))
.build();
messageDialog.show(linkContent);
} else {
showInfoDialog(getString(R.string.info_dialog_messenger_not_found));
}