2014-07-26 81 views
2

我有一個應用程序,使用戶可以在Facebook上分享圖像;我希望自動的應用程序的鏈接可以與圖像共享。在Facebook上分享圖像+ AppLink Android

這是我使用的代碼,但該鏈接的部分不理並沒有出現:

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
shareIntent.setType("image/png"); 
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath))); 
shareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com"); //doesn't appear 
PackageManager pm = context.getPackageManager(); 
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); 
for (final ResolveInfo app : activityList) 
{ 

    Log.d("CitationsManager-ShareOnFb", app.activityInfo.name); 
    if ((app.activityInfo.name).contains("facebook.katana") 
     || (app.activityInfo.name).contains("facebook.composer.shareintent") 
     || (app.activityInfo.name).contains("facebook.composer.activity")) 
    { 
     final ActivityInfo activity = app.activityInfo; 
     final ComponentName name = new ComponentName(
      activity.applicationInfo.packageName, activity.name); 
     shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
     shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
      | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED 
      | Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     shareIntent.setComponent(name); 
     context.startActivity(shareIntent); 
     break; 
    } 

你有什麼想法,我怎麼能知道檢查結果?我已閱讀有關該主題的問題,但找不到合適的解決方案。

由於

+0

我也有幾乎相似的要求。你有同樣的解決方案嗎? –

回答

2

提供的Facebook類shareDialog Facebook上共享圖像或內容。你可以閱讀更多的細節,檢查here

 shareDialog = new ShareDialog(this); // initialize facebook shareDialog. 
    button.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
    if (ShareDialog.canShow(ShareLinkContent.class)) { 
     ShareLinkContent linkContent = new ShareLinkContent.Builder() 
      .setContentTitle("Android Facebook Integration and Login Tutorial") 
      .setImageUrl(Uri.parse("https://www.studytutorial.in/ 
        wp-content/uploads/2017/02/FacebookLoginButton-min-300x136.png")) 
      .setContentDescription(
        "This tutorial explains how to integrate Facebook and Login 
        through Android Application") 
      .setContentUrl(Uri.parse("https://www.studytutorial.in/ 
         android-facebook-integration-and-login-tutorial")) 
      .build(); 
       shareDialog.show(linkContent); // Show facebook ShareDialog 
     } 
    } 
}); 
+1

不錯的作品對我來說很完美:) –