【问题标题】:I want To share Multiple Picture With Single Caption我想用一个标题分享多张图片
【发布时间】:2018-08-14 10:45:18
【问题描述】:

我想分享多张带有单个标题的图片,该标题显示在一张图片上,而不是所有图片上。但是标题将显示在一次共享的每张图片上。

这是我的代码

private void pic_with_data() {

    Intent shareIntent = new Intent(); 
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setPackage("com.whatsapp");
    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUriArray);
    shareIntent.putExtra(Intent.EXTRA_TEXT, "Download this App");
    shareIntent.setType("text/plain");

    shareIntent.setType("image/jpeg");
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    try {
        startActivity(Intent.createChooser(shareIntent, "Share Image!"));
        startActivity(shareIntent);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(this, "Whatsapp have not been installed.", Toast.LENGTH_SHORT).show();
    }
}

【问题讨论】:

  • 您所说的单个标题是什么意思,它只显示在一张图片上,而不是全部。但是标题会显示在每张图片上 ??
  • 每张图片中的文本都相同为此我建议创建带有文本的位图并将所有图像放入数组列表共享列表中
  • Mohit,请分享一些方法
  • 我可以分享你的方法.. 但我所指的过程将在图像上打印文本,然后将转换为位图,创建后不会更改(如书签),但我可以看到你是发送 下载此应用 消息以及手动输入的每张图片

标签: android android-intent share whatsapp


【解决方案1】:

使用Intent.ACTION_SEND_MULTIPLE 而不是Intent.ACTION_SEND

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
intent.setType("image/jpeg"); /* This example is sharing jpeg images. */

ArrayList<Uri> files = new ArrayList<Uri>();

for(String path : filesToSend /* List of the files you want to send */) {
    File file = new File(path);
    Uri uri = Uri.fromFile(file);
    files.add(uri);
}

intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(intent);

请记住,从 API 24 开始,共享文件 URI 将导致 FileUriExposedException。要解决此问题,您可以将 compileSdkVersion 切换为 23 或更低,也可以使用带有 FileProvider 的内容 URI。

【讨论】:

  • 但每张图片下方仍显示文字,这很烦人。我只想分享第一张图片下方的文字,而不是其他人。
【解决方案2】:

我没有机会编译这个,但这应该可以工作

val files: ArrayList<Uri> = arrayListOf()
    // add files here in `files` variable

    startActivity(Intent(Intent.ACTION_GET_CONTENT)
        .setType("image/*")
        .putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
        .putParcelableArrayListExtra(Intent.EXTRA_STREAM, files))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    • 2021-07-07
    相关资源
    最近更新 更多