Share Image On Other Apps Not Working In Oreo 8.0
I am using this code to share the image on Whatsapp, Facebook, and Instagram etc. This code works fine below API 25 but Not Working above API 25. Intent share = new Intent('android
Solution 1:
If targetSdkVersion is higher than 24, then Provider is used to grant access.
Create an xml file : res\xml\provider_paths.xml
<?xml version="1.0" encoding="utf-8"?><pathsxmlns:android="http://schemas.android.com/apk/res/android"><external-pathname="external_files"path="."/></paths>
now Add a Provider in AndroidManifest.xml file
<provider
android:name="android.support.v4.content.FileProvider"android:authorities="${applicationId}.provider"android:exported="false"android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
and replace this with your code
Intentshare=newIntent("android.intent.action.SEND");
share.setType("image/jpeg");
Uriuri= FileProvider.getUriForFile(MainActivity.this, BuildConfig.APPLICATION_ID+ ".provider",newFile(this.imgUrl));
share.putExtra("android.intent.extra.STREAM", uri);
startActivity(Intent.createChooser(share, "via"));
Update
<?xml version="1.0" encoding="utf-8"?><pathsxmlns:android="http://schemas.android.com/apk/res/android"><files-pathname="external_files"path="."/><cache-pathname="external_files"path="."/><external-pathname="external_files"path="."/><external-files-pathname="external_files"path="."/><external-cache-pathname="external_files"path="."/></paths>
Solution 2:
First make sure you have added permission
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Then use this code
Intentshare=newIntent(Intent.ACTION_SEND);
share.setType("image/jpeg");
UriimageUri= Uri.parse(this.imgUrl);
share.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(share, "Select"));
Solution 3:
Try this:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent,getResources().getText(R.string.send_to)));
Post a Comment for "Share Image On Other Apps Not Working In Oreo 8.0"