Skip to content Skip to sidebar Skip to footer

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"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="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

Intent share = new Intent("android.intent.action.SEND");
            share.setType("image/jpeg");
Uri uri = FileProvider.getUriForFile(MainActivity.this, BuildConfig.APPLICATION_ID+ ".provider",new File(this.imgUrl));
            share.putExtra("android.intent.extra.STREAM", uri);

            startActivity(Intent.createChooser(share, "via"));

Update

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="external_files" path="."/>
<cache-path name="external_files" path="."/>
<external-path name="external_files" path="."/>
<external-files-path name="external_files" path="."/>
<external-cache-path name="external_files" path="."/>
</paths>

Solution 2:

First make sure you have added permission

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Then use this code

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
Uri imageUri =  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"