我想用一个字幕共享多张图片 [英] I want To share Multiple Picture With Single Caption

查看:68
本文介绍了我想用一个字幕共享多张图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想共享一个标题的多张图片,而该标题只显示在一张图像上,而不是全部显示在一张图像上.但是标题将显示在一次共享的每张照片上.

I want to share multiple picture with single caption which is shown on one image not on all of them. But caption will show on every pic which is shared at one time.

这是我的代码

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

推荐答案

使用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或更低版本,也可以将内容URI与文件提供商.

Remember, Starting in API 24, sharing file URIs will cause a FileUriExposedException. To remedy this, you can either switch your compileSdkVersion to 23 or lower or you can use content URIs with a FileProvider.

这篇关于我想用一个字幕共享多张图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆