【问题标题】:Share Intent.ACTION_SEND分享意图。ACTION_SEND
【发布时间】:2014-03-18 03:53:09
【问题描述】:

我很想分享一张带有文字或网址的图片。 我正在使用此代码,但我仅共享图像,并且更改“类型”的顺序使我共享两者,但仅作为电子邮件/ gmail 我究竟做错了什么?我的代码是:

编辑1

Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);
           share.setType("*/*");
           share.putExtra(Intent.EXTRA_STREAM,               Uri.parse("file:///sdcard/Wallpaper/1.jpg"));
           share.putExtra(Intent.EXTRA_TEXT, "helloworld");
           startActivity(Intent.createChooser(share, (getApplicationContext().getString(R.string.condividi))));

【问题讨论】:

  • 在您提到 ACTION_SEND 的问题中,即您想发送单个文件,但在您的代码中您想发送多个文件并仅提供单个 URI。你想做什么?

标签: android image android-intent share


【解决方案1】:

试试这个

File DoutFile = new File(path);

        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("image/*");

        share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(DoutFile));
        share.putExtra(Intent.EXTRA_TEXT,
                "" + getResources().getString(R.string.app_name));

        startActivity(Intent.createChooser(share, "Share Image"));

【讨论】:

    【解决方案2】:

    同时为文本指定 MIME 类型。 "text/plain" 是文本数据 MIME 的类型。尝试使用"*/*" 作为 MIME,这样您就可以发送任何通用数据类型。

    还可以尝试将ACTION_SEND 更改为ACTION_SEND_MULTIPLE,它专门用于传递多个数据。

    有关 ACTION_SEND_MULTPLE 和处理 MIME 类型的更多信息:

    http://developer.android.com/reference/android/content/Intent.html

    【讨论】:

    • 如果我尝试在 facebook 或 whatsapp 上分享它,我会出现“只附上一张照片或视频”的祝酒词
    • 看,你的问题已经解决了。您现在可以使用此代码共享一个带有文本的文件。你还需要什么?
    • 您到底需要什么?您需要发送带文字的图片吗?现在不是这样吗? :)
    • 对于发送多个文件,您可以使用数组列表并循环并逐个发送,如果有帮助,请不要忘记投票并接受答案。 :) 干杯
    • 查看此链接。它会告诉你为什么stackoverflow.com/questions/7076717/…
    【解决方案3】:

    如果您想发送多个文件,请使用以下代码:-

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND_MULTIPLE);
    intent.putExtra(Intent.EXTRA_SUBJECT, "Add any subject");
    intent.setType("image/*"); /* sharing any type of image. Modify to your need */
    
    ArrayList<Uri> files = new ArrayList<Uri>();
    
    for(String path : filesToSend /* List of images you want to send */) {
        File file = new File(path);
        Uri uri = Uri.fromFile(file);
        files.add(uri);
    }
    
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files); /* adding files to intent */
    startActivity(intent);
    

    【讨论】:

    • 我必须使用 filesToSend 作为变量?
    • **filesToSend ** 是字符串数组,其中包含所有图像的路径,例如 http://url of image/ab.pnghttp://url of image/abc.pnghttp://url of image/abcd.png 等。
    • 但是图片已经在手机上,路径是我预定义的
    • @GappAiello 首先您要发送单个文件还是多个文件?您的问题的标题和发布的代码让我感到困惑。
    • 我想用文字发送路径“file://sdcard/Wallpaper/1.jpg”的图片
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    • 2018-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    相关资源
    最近更新 更多