ACTION_SEND sending both an Image and Text in the same Intent

前端 未结 1 1630
野性不改
野性不改 2021-01-14 02:38

So I would like to do something like:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(myMessageAsImage));
inte         


        
相关标签:
1条回答
  • 2021-01-14 03:01

    I don't know what you mean by 'common way' but I think you should set the type to intent.setType("image/*");.

    EDIT:

    How you send data with intent depends on the availability of apps that filter your particular action. Apps that handle ACTION_SEND may not handle ACTION_SEND_MULTIPLE. Clicking Share on HTC Gallery produces a list of applications that handle image, single or multiple. If you choose Mail then you can select multiple images. But if you choose Facebook or Peep then you can only select one image. This is my simple solution if you want to do the reverse of HTC Gallery, that is: user chooses image(s) first then you show him all compatible apps based on how many he selected.

    // assuming uris is a list of Uri
    Intent intent = null;
    if (uris.size > 1){
    intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    } else if (uris.size() == 1) {
    intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));}
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_TEXT, "Some message");
    startActivity(Intent.createChooser(intent,"compatible apps:"));
    
    0 讨论(0)
提交回复
热议问题