Reputation: 45
I am trying to share an image using intents. Please find the function for the same.
if(view.getId()==R.id.sendImage){
Uri imgUri=Uri.parse("android.resource://com.example.watchyalist/mipmap/"+R.mipmap.test);
intent=new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM,imgUri);
intent.putExtra(intent.EXTRA_TEXT,"Please find the image");
chooser=Intent.createChooser(intent,"Choose the app");
startActivity(chooser);
}
Here test is the image that I am referring to,it sends bin file when shared via whatsapp. I tried using ic_launcher, then it says failed sharing. Here is a snap shot of my manifest file
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
I am unable to understand it. I tried changing the manifest tag to drawable and accordingly keeping the imag in drawable and making changes accordingly still no luck. I have kept image in the mipmap-anydpi-v26 folder in project,and also tried changing the location but no use.Could anyone please help? Thanks!
Upvotes: 1
Views: 31
Reputation: 1007624
EXTRA_STREAM
is documented to take a Uri
with a content:
scheme. android.resource:
is not content:
. There is no requirement for any app to know how to handle your Uri
when they receive it from your app. Plus, your Uri
ends in a semi-random number (whatever R.mipmap.test
happens to be for this build).
Please copy the image to a file (e.g., in getCacheDir()
), then use FileProvider
and getUriForFile()
to get the Uri
to use for EXTRA_STREAM
.
Upvotes: 1