首页 > 解决方案 > 在同一条消息中共享带有一些文本的图像

问题描述

我希望在图像下添加一条文本消息(未打印在图像上),因此当我单击共享按钮时,图像和文本消息将作为一条消息共享,如下所示:

在此处输入图像描述

我共享图像的代码如下所示:

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在同一条短信或电子邮件等中添加图像下的文本(作为未打印在图像上的文本)。

标签: androidimagetextshare

解决方案


以下代码片段应该可以工作。我们将图像添加到 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 ..."));
}

推荐阅读