本文介绍了使用shareIntent时,如何使用Intent.ACTION_SEND_MULTIPLE发送多种数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文档中很明显,您可以使用以下方式发送多条数据:

Its pretty clear in the documentation that you can send multiple pieces of data with:

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));

但是,从那一行看来:shareIntent.setType("image/*");所有片段必须是相同的数据类型.如果我想发送图片(图片/jpeg)和标题标签(文本/纯文本)中应附带的主题标签,该怎么办?

but it seems, from that one line: shareIntent.setType("image/*"); that all pieces have to be the same data type. What If I wanted to send a picture(image/jpeg) and a hashtag that should go along with in the caption (text/plain)?

我如何在一个shareIntent中处理多种内容?是否可以将2个shareIntent发送到同一活动?我该如何处理?

How would I handle multiple kinds of content in one shareIntent? Is it possible to send 2 shareIntents to the same activity? How would I handle this?

推荐答案

如果您的目标是与文本共享一张图片,这是我建议的代码:

If your goal is to share one picture with text, this is the code I would suggest:

String text = "Look at my awesome picture";
Uri pictureUri = Uri.parse("file://my_picture");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_STREAM, pictureUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share images..."));

这篇关于使用shareIntent时,如何使用Intent.ACTION_SEND_MULTIPLE发送多种数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 17:45