2013-12-17 44 views
3

我已經使用共享對話框成功共享了facebook的鏈接。如何分享未安裝Facebook應用的Facebook鏈接?

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

但是,它需要安裝Facebook應用程序。那麼,我怎樣才能分享到臉譜Facebook應用程序安裝? 感謝

+0

請看看[發佈到飼料(https://developers.facebook.com/docs/android/publish-to-feed/) –

+0

嗨@Ketan,所以我需要實現登錄按鈕?有什麼辦法只實現分享按鈕,並檢查用戶是否不登錄 - >打開登錄頁面。 – hoangmeo325

回答

2
if (!facebookAppFound) { 
    String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare; 
    intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl)); 
} 
+0

你可以多說一下'facebookAppFound'嗎? – dachi

5
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);