How to show an image through an intent being compatible with different apps

前端 未结 4 933
Happy的楠姐
Happy的楠姐 2021-01-03 12:22

I\'m trying to share an image I have previously saved on disk, sending an Intent.ACTION_SEND. The problem is that I can\'t find a way to be compatible with diff

4条回答
  •  温柔的废话
    2021-01-03 13:17

    I finally solved the problem storing the image at the MediaStore. Instead of using the URI of the File what I do is:

    String agendaFilename = agendaFile.getAbsolutePath();
    
    final ContentValues values = new ContentValues(2);
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    values.put(MediaStore.Images.Media.DATA, agendaFilename);
    final Uri contentUriFile = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    

    And finally I use contentUriFile:

    final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("image/jpg");
    intent.putExtra(android.content.Intent.EXTRA_STREAM, contentUriFile);
    startActivity(Intent.createChooser(intent, "title"));
    

提交回复
热议问题