android - 在同一条消息中共享带有一些文本的图像
问题描述
我希望在图像下添加一条文本消息(未打印在图像上),因此当我单击共享按钮时,图像和文本消息将作为一条消息共享,如下所示:
我共享图像的代码如下所示:
public void shareImage(View view) {
Intent shareIntent = new Intent();
Uri photoURI = FileProvider.getUriForFile(this, "com.abcd.myapp", theImage);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, photoURI);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Image with ..."));
}
如何Image created by: abcd.com
在同一条短信或电子邮件等中添加图像下的文本(作为未打印在图像上的文本)。
解决方案
以下代码片段应该可以工作。我们将图像添加到 MediaStore。
public void shareImage(View view) {
Intent shareIntent = new Intent();
shareIntent.putExtra(Intent.EXTRA_TEXT, Constant.SHARE_MESSAGE
+ Constant.SHARE_URL);
Uri photoURI = FileProvider.getUriForFile(this, "com.abcd.myapp", theImage);
Bitmap bm = BitmapFactory.decodeFile(photoURI);
String url= MediaStore.Images.Media.insertImage(this.getContentResolver(), bm, "title", "description");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Image with ..."));
}
推荐阅读
- python-3.x - 如何处理差异音频文件的 MFCC 功能差异
- json - Spring Boot 2 处理表单数据,其中 json 是键的值
- amazon-web-services - 如何对aws codepipeline更改集进行排队
- html - HTML default namespace vs. explicit namespace
- javascript - Javascript 扩展运算符可以包含对象的未定义字段吗?
- uwp - UWP 多视图:关闭主视图时关闭所有辅助视图
- jquery - 取消单身日期
- codenameone - 在代号中从一个点到另一个点画直线
- json - 使用动态密钥解组 json
- python - 为什么当声明为变量名称时,我不能使用 OpenCV 将图像复制并粘贴到某个位置?