如何分享图片+文字的机器人使用ACTION_SEND?机器人、文字、图片、ACTION_SEND

由网友(我希望你快乐)分享简介:我想分享文字+图片使用ACTION_SEND在Android中,我使用低于code,我只能共享图片,但我不能分享它的文字,I want to share Text + Image using ACTION_SEND in android, i am using below code, i can share only...

我想分享文字+图片使用ACTION_SEND在Android中,我使用低于code,我只能共享图片,但我不能分享它的文字,

I want to share Text + Image 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);

您可以请提供解决方案?

Can you please provide solutions ?

推荐答案

您可以通过以下方式分享纯文本这些codeS

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

让你充分code(图像+文字)成为

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"));
阅读全文

相关推荐

最新文章