【问题标题】:How to add Title,Description and Image with Facebook Share Intent ?如何使用 Facebook Share Intent 添加标题、描述和图像?
【发布时间】:2014-01-28 05:57:48
【问题描述】:

我在 android 中使用以下代码进行 fb 分享 -

topics_fb_share.setOnClickListener(new OnClickListener(){
           @Override
           public void onClick(View v) {
               String urlToShare = "http://stackoverflow.com/questions/7545254";
               Intent intent = new Intent(Intent.ACTION_SEND);
               intent.setType("text/plain");
               // intent.putExtra(Intent.EXTRA_SUBJECT, "Foo bar"); // Has no effect!
               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);
              }
    });

如何添加标题、描述和图片 在此先感谢

【问题讨论】:

    标签: android facebook facebook-sharer android-facebook


    【解决方案1】:

    你可以通过这个添加图片

    intent .setAction(Intent.ACTION_SEND);
    intent .putExtra(Intent.EXTRA_STREAM, Uri.parse(MediaStore.Images.Media
    .insertImage(getContentResolver(), source, title, description)));
    intent .setType("image/jpeg");
    startActivity(Intent.createChooser(shareIntent,
    getResources().getString(R.string.send_to)));
    

    【讨论】:

      猜你喜欢
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 2011-02-10
      • 1970-01-01
      • 2020-09-28
      • 1970-01-01
      相关资源
      最近更新 更多