How to Share Image + Text together using ACTION_SEND in android?

前端 未结 11 1895
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 09:59

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          


        
11条回答
  •  不知归路
    2020-11-28 10:28

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

    I just replaced image/* with */*

    update:

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

提交回复
热议问题