android - 在 Facebook 上分享 图片+AppLink Android

标签 android facebook image hyperlink share

我有一个应用程序,可以让用户在 Facebook 上分享图像;我希望应用程序的链接可以自动与图像一起共享。

这是我正在使用的代码,但带有链接的部分只是被忽略并且没有出现:

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;
    }

你知道我怎样才能得到结果吗?我已阅读有关该主题的问题,但找不到合适的解决方案。

谢谢

最佳答案

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

关于android - 在 Facebook 上分享 图片+AppLink Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24971204/

相关文章:

ios - 如何在 iOS SDK 3.0 上检查和更新 Facebook token 的状态?

image - 顶部标题 Img 留在计算机上 & 中心在手机和平​​板电脑上

c# - 如何将表单中的面板保存为图片?

python - 检查两个图像的 RGB 值之间的差异

android - OKHTTP 3 跟踪分段上传进度

java - android中的开关盒问题

java - Sharedpreferences 在 SetText #android 时抛出空指针

android - 使用 monkey runner 验证

Android Facebook api 3.0 错误 : Cannot call LoginActivity with a null calling package

iPhone facebook 连接电子邮件返回 null