Sharing Image Using Intent On Whats App Getting Error Sharing Failed
I am loading single jpg image from drawable folder set file provider permission in manifest but when i share image on whatsapp i got error sharing failed please try again.When i sh
Solution 1:
privatevoidshareImage(Uri imagePath) {
IntentsharingIntent=newIntent(Intent.ACTION_SEND);
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, imagePath);
//sharingIntent.setPackage("com.whatsapp"); for whatsapp only
startActivity(Intent.createChooser(sharingIntent, "Share Image Using"));// for all generic options
}
Finaly in your manifest Add this without fail
<activityandroid:name=".YourActivity"android:icon="@drawable/share_this"android:label="@string/shared_activity" ><intent-filter><actionandroid:name="android.intent.action.SEND" /><!-- Send
action required to display activity in share list --><categoryandroid:name="android.intent.category.DEFAULT" /><!--
Make activity default to launch --><!-- Mime type i.e. what can be shared with this activity only image and text --><dataandroid:mimeType="image/*" /><dataandroid:mimeType="text/*" /></intent-filter></activity>
This will owrk
Solution 2:
ArrayList<Uri> uriArrayList = newArrayList<>();
uriArrayList.add(getUriFromFile(your file path))
Intentintent=newIntent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.setType("image/*");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, myFilesUriList);
startActivity(intent);
public Uri getUriFromFile(File theSrcPath) {
UrirequirdUri=null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
requirdUri = FileProvider.getUriForFile(theCtx,
theCtx.getApplicationContext().getPackageName() + PROVIDER_FILE_EXTENSION,
theSrcPath);
} else {
requirdUri = Uri.fromFile(theSrcPath);
}
}
Post a Comment for "Sharing Image Using Intent On Whats App Getting Error Sharing Failed"