[英]Android - Java - Intent to send facebook chat message (facebook disabled xmpp)
***Facebook deprecated xmpp api. *** Facebook 已弃用 xmpp api。
Is there a way to open an intent (or pass data to fb) to send chat message on android device?有没有办法打开一个意图(或将数据传递给 fb)以在 android 设备上发送聊天消息? Facebook & Messenger apps installed on the device.
安装在设备上的 Facebook 和 Messenger 应用程序。
Thanks :-)谢谢 :-)
You need to pass uri to the intent Here 100005727832736 is the user id of the person who you want to message to
您需要将 uri 传递给意图这里100005727832736是您要向其发送消息的人的用户 ID
Uri uri = Uri.parse("fb-messenger://user/100005727832736");
Here is my sample code这是我的示例代码
Uri uri = Uri.parse("fb-messenger://user/100005727832736");
Intent toMessenger= new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(toMessenger);
}
catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(context, "Please Install Facebook Messenger", Toast.LENGTH_LONG).show();
}
}
This is what worked for me and i haven not tested this for some time now.这对我有用,我已经有一段时间没有测试过了。
To launch facebook app let urlString = "fb://page/your_fb_page_id"要启动facebook 应用程序让 urlString = "fb://page/your_fb_page_id"
To launch facebook messenger let urlString = "fb-messenger://user/your_fb_page_id"要启动facebook 信使让 urlString = "fb-messenger://user/your_fb_page_id"
FB page id is usually numeric. FB 页面 id 通常是数字。 To get it, goto Find My FB ID input your profile url, something like www.facebook.com/edgedevstudio then click "Find Numberic ID".
要获得它,请转到“查找我的 FB ID”,输入您的个人资料网址,例如www.facebook.com/edgedevstudio,然后单击“查找数字 ID”。
Voila, you now have your fb numeric id.瞧,你现在有了你的 fb 数字 ID。 replace "your_fb_page_id" with the generated Numeric ID
用生成的数字 ID 替换“your_fb_page_id”
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(urlString))
if (intent.resolveActivity(packageManager) != null) //check if app is available to handle the implicit intent
startActivity(intent)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.