【问题标题】:Issue in share text and image both using share intent android共享文本和图像中的问题都使用共享意图android
【发布时间】:2014-08-05 06:56:02
【问题描述】:

你好朋友,我想在 android 中使用共享意图同时共享文本和 sdcard 图像 下面是我在按钮单击时的代码。

    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.setType("text/plain,image/*");
    String imagePath = Environment.getExternalStorageDirectory()
            + "/myfolder/1407156604780.png";
    File imageFileToShare = new File(imagePath);
    Uri uri = Uri.fromFile(imageFileToShare);
    share.putExtra(Intent.EXTRA_STREAM, uri);
    share.putExtra(Intent.EXTRA_SUBJECT, "Title Of The Post");
    share.putExtra(Intent.EXTRA_TEXT, "fdsfdsfdsfds");
    startActivity(Intent.createChooser(share, "Share image to..."));

使用上述代码共享对话框已打开,但 facebook 选项未显示给我,但在我的设备 facebook 应用程序中已经存在,所以我可以为文本设置多个 setType 属性以及图片分享到 facebook

【问题讨论】:

  • 当您在 fab 上分享您在对话框中看到的内容时?
  • 试试 share.setType("text/plain");除了那一行之外,我的代码看起来相同并且工作正常。
  • 看看这个..stackoverflow.com/questions/8296605/…它会帮助你很多。
  • 嗨,我试过了,但是使用意图你不能分享文本默认你只能分享文本的图像你必须在对话框显示后手动输入文本 twitte 是允许的,但 facebook 是不允许的默认文本跨度>
  • @ Born To Win : 当我使用 setType("/") 和 facebook 选项时,它会给我像 " 这样的祝酒词"请仅附上照片或单个视频”

标签: android facebook android-intent


【解决方案1】:

首先,facebook 不允许使用共享意图共享文本,而是我们需要使用 facebook sdk。除 facebook 和 instagram 之外的所有其他社交媒体都支持以下代码。但你可以在 poopup dil​​og 中看到 facebook 和所有其他已安装的应用程序

      Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
            shareIntent.putExtra(Intent.EXTRA_TEXT, "text");
            shareIntent.putExtra(Intent.EXTRA_STREAM, image);
            shareIntent.setType("image/*");
            // Launch sharing dialog for image
            startActivity(Intent.createChooser(shareIntent, "Share"));

试试吧..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多