如何共享安装链接至Facebook没有Facebook应用程序? [英] How to share a link to facebook without facebook app installed?

查看:237
本文介绍了如何共享安装链接至Facebook没有Facebook应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的共享链接成功地利用共享对话框到Facebook。

https://developers.facebook.com/docs/android/share-dialog /

但是,它需要安装Facebook应用程序。所以,我怎么能分享到Facebook这出Facebook应用程序安装? 谢谢

解决方案

 意向意图=新的意图(Intent.ACTION_SEND);
intent.setType(text / plain的);
intent.putExtra(Intent.EXTRA_TEXT,urlToShare);
//看看官方的Facebook应用程序被发现
布尔facebookAppFound = FALSE;
名单< ResolveInfo>火柴= getPackageManager()queryIntentActivities(意向,0)。
对于(ResolveInfo信息:匹配){
如果(info.activityInfo.packageName.toLowerCase()。startsWith(com.facebook)){
intent.setPackage(info.activityInfo.packageName);
facebookAppFound = TRUE;
打破; }}
//作为后备,推出shar​​er.php在浏览器
如果(!facebookAppFound){
 字符串sharerUrl =htt​​ps://www.facebook.com/sharer/sharer.php?u=+ urlToShare;
意图=新的意图(Intent.ACTION_VIEW,Uri.parse(sharerUrl));
}
startActivity(意向);
 

I had shared link to facebook using share dialog successfully.

https://developers.facebook.com/docs/android/share-dialog/

But it requires facebook app installed. So, How can i share to facebook which out facebook application install? Thanks

解决方案

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, urlToShare);
// See if official Facebook app is found
boolean facebookAppFound = false;
List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo info : matches) {
if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook")) {
intent.setPackage(info.activityInfo.packageName);
facebookAppFound = true;
break;  }}
// As fallback, launch sharer.php in a browser
if (!facebookAppFound) {
 String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}
startActivity(intent);

这篇关于如何共享安装链接至Facebook没有Facebook应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆