I want To share Multiple Picture With Single Caption

元气小坏坏 提交于 2019-12-23 23:04:32

问题


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.

Here is my code

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


回答1:


Use Intent.ACTION_SEND_MULTIPLE instead of 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);

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.



来源:https://stackoverflow.com/questions/51839604/i-want-to-share-multiple-picture-with-single-caption

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!