【问题标题】:share image with caption to social media using intent android使用 Intent android 将带有标题的图像分享到社交媒体
【发布时间】:2015-10-14 18:58:56
【问题描述】:

我在使用 Intent 共享图像时遇到了一个小问题。这是我的情况,当我使用以下代码时,我想分享带有标题的图像(标题可能是链接或文本)

Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");

            shareIntent.setType("image/*");

            Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                    R.drawable.whatsapp_promotion);
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);

            String path = MediaStore.Images.Media.insertImage(
                    getContentResolver(), bitmap, null, null);
            Uri uri = Uri.parse(path);
            shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
            shareIntent
                    .putExtra(
                            Intent.EXTRA_TEXT,
                            "**my message with URL **");

            startActivity(Intent.createChooser(shareIntent, "Share Via..."));

我可以与 hangout、whatsapp、twitter 等分享,但无法与 facebook 分享。所以我决定的是一张带有标题的图片,可以在whatsapp、hangout、facebook等中分享,

怎么做,请帮帮我

提前致谢

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    您不能通过 Intent 将图像和文本分享到 Facebook。为此,您必须使用 Facebook API。

    【讨论】:

    • 是的,我读到了这一点,但我们可以与 facebook 分享图像知道,我们可以为该图像添加标题吗??
    • 图片的标题是什么意思?
    • 请参考whatsapp..当我们与朋友分享图像时,我们可以为该图像添加标题(标题)知道..我需要相同的概念,这就是全部
    • 我不认为这是可能的。如果你想与文本一起分享图像,你最好使用 Facebook API,如果你只想分享文本,最好使用 Intent
    【解决方案2】:

    您需要 Facebook sdk,然后您可以这样做:

        SharePhoto photo = new SharePhoto.Builder().setBitmap(
                getYourBitmapMethod()).build();
    
        SharePhotoContent content = new SharePhotoContent.Builder()
                .addPhoto(photo).setRef("This is a test").build();
    
        ShareDialog.show(YourActivity.this, content);
    

    【讨论】:

    • 感谢分享代码..但请参考whatsapp..当我们与朋友分享图像时,有一个标题(标题或标题)可用知道..所以我想要那种与标题共享图像的代码
    【解决方案3】:

    这是在 facebook 上分享照片的文档 https://developers.facebook.com/docs/sharing/android#photos

    这是为您的图像构建内容的代码 sn-p

    Bitmap image = ...
    SharePhoto photo = new SharePhoto.Builder()
            .setBitmap(image)
            .setCaption("Enter your caption")
            .build();
    SharePhotoContent content = new SharePhotoContent.Builder()
            .addPhoto(photo)
            .build();
    

    然后分享ShareDialog.show(YourActivity.this, content);

    在 facebook 上分享的完整文档在这里:https://developers.facebook.com/docs/sharing/android

    【讨论】:

      猜你喜欢
      • 2019-08-24
      • 1970-01-01
      • 1970-01-01
      • 2013-01-28
      • 2016-07-22
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多