我已成功使用分享对话框分享链接到Facebook。
https://developers.facebook.com/docs/android/share-dialog/
但需要安装Facebook应用程序。那么,如果没有安装Facebook应用程序,我该如何分享到Facebook?谢谢。
我已成功使用分享对话框分享链接到Facebook。
https://developers.facebook.com/docs/android/share-dialog/
但需要安装Facebook应用程序。那么,如果没有安装Facebook应用程序,我该如何分享到Facebook?谢谢。
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);
if (!facebookAppFound) {
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}
facebookAppFound
的内容吗? - dachi