本文介绍了如何在android中使用ACTION_SEND一起共享图像+文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 android 中使用 ACTION_SEND 一起共享文本 + 图像,我使用下面的代码,我只能共享图像但我不能与它共享文本,

I want to share Text + Image together using ACTION_SEND in android, I am using below code, I can share only Image but i can not share Text with it,

private Uri imageUri;
private Intent intent;

imageUri = Uri.parse("android.resource://" + getPackageName()+ "/drawable/" + "ic_launcher");
intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hello");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
intent.setType("image/*");
startActivity(intent);

对此有什么帮助吗?

推荐答案

你可以通过这些代码分享纯文本

you can share plain text by these codes

String shareBody = "Here is the share content body";
    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share_using)));

所以你的完整代码(你的图片+文字)变成了

so your full code (your image+text) becomes

      private Uri imageUri;
      private Intent intent;

            imageUri = Uri.parse("android.resource://" + getPackageName()
                    + "/drawable/" + "ic_launcher");

            intent = new Intent(Intent.ACTION_SEND);
//text
            intent.putExtra(Intent.EXTRA_TEXT, "Hello");
//image
            intent.putExtra(Intent.EXTRA_STREAM, imageUri);
//type of things
            intent.setType("*/*");
//sending
            startActivity(intent);

我刚刚用 */*

更新:

Uri imageUri = Uri.parse("android.resource://" + getPackageName()
        + "/drawable/" + "ic_launcher");
 Intent shareIntent = new Intent();
 shareIntent.setAction(Intent.ACTION_SEND);
 shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello");
 shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
 shareIntent.setType("image/jpeg");
 shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
 startActivity(Intent.createChooser(shareIntent, "send"));

这篇关于如何在android中使用ACTION_SEND一起共享图像+文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 20:58