Hello!

Is it possible to share a picture with an android application, for example, in VK or somewhere else. Plain text is sent without problems, but I can not figure it out with a picture. Is it even possible to do this?

When I click on the button, I get the address of the image from the database (I use sugar) and try to send it using share.

In the application, the picture is displayed, but I can not send.

@Override public void onClick(View view) { Contact img = Contact.findById(Contact.class, idInt); // получаю из БД адрес картинки int photoId = img.photoId; switch (view.getId()) { case R.id.fab: Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/jpeg"); share.putExtra(Intent.EXTRA_STREAM, photoId); startActivity(Intent.createChooser(share, "Share Image")); break; } } 
  • What is the address of the image (variable photoId )? - post_zeew
  • Yes, it doesn’t matter, you can add a direct address instead, it still doesn’t work - Artsait
  • And where is the picture stored? - post_zeew
  • R.drawable.bolshrastmsl - Artsait

1 answer 1

It seems to understand

  Uri imageUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "bolshrastmsl"); 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")); break;