How to share an android photo

Asked

Viewed 188 times

0

I have this drawable:

String nome_foto = itens.get(pos).nome_foto;
        int drawableId = getResources().getIdentifier(nome_foto, "drawable", getPackageName());
        Drawable drawable = getDrawable(drawableId);

I have this drawable with the photo, how can I use it in sharing the Android.

I thought of something like this:

Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_STREAM,Aki precisa de um uri );
        sendIntent.setType("image/jpg");
        startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.compartilhar)));

But you need a uri I don’t know how to do?

3 answers

2


You can use Share Action Provider, basically it’s a sharing mechanism helps you share content. For more information android documentation that he will help.

0

You can share a photo as long as there is a path to it. And the URI identifies this path when assigned a value in string.

Search the image on your device via the path given in the URI]:

Uri imgUri=Uri.parse("file:///data/data/MINHA_PASTA_ANDROID/minhaimage.png");
imgview.setImageUri(imgUri);

Now you have a URI called: imgUri

...

sendIntent.putExtra(Intent.EXTRA_STREAM,imgUri );

...

However, sometimes you may want to take from the folder drawable:

Uri imgUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
                getResources().getResourcePackageName(R.drawable.ic_launcher) + '/' +
                getResources().getResourceTypeName(R.drawable.ic_launcher) + '/' +
                getResources().getResourceEntryName(R.drawable.ic_launcher) );

//Testando
imageView.setImageURI(imageUri);

-3

Try this way:

Uri uri = Uri.parse("android.resource://your.package.here/drawable/image_name");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.