romatroskin / social_share_plugin

Social Share to Facebook and Instagram Flutter plugin.
BSD 2-Clause "Simplified" License
41 stars 86 forks source link

Sharing to Instagram Feed Broken #23

Closed segidev closed 4 years ago

segidev commented 4 years ago

Hi there,

actually there is a bug from Instagram. When you try to share to the Feed, Instagram isn't able to find the shared image. It works for Direct and Story without problem.

The actual issue is known and Facebook wants to take care of it. You find the issue here: https://developers.facebook.com/support/bugs/1326888287510350/

As a workaround and maybe a future fallback / replacement i tried to use the MediaStore instead and it works with it. The only drawback since i didn't try out enough is that it creates a copy of the user image in the Gallery.

private void instagramShare(String type, String imagePath) {
    final Context context = getApplicationContext();
    final ContentResolver contentResolver = context.getContentResolver();
    try {
        String savedImageURL = MediaStore.Images.Media.insertImage(
                getApplicationContext().getContentResolver(),
                imagePath,
                "temp image",
                "image to share to Instagram"
        );
        Uri savedImageURI = Uri.parse(savedImageURL);

        final Intent share = new Intent(Intent.ACTION_SEND);
        share.setType(type);
        share.putExtra(Intent.EXTRA_STREAM, savedImageURI);
        share.setPackage(INSTAGRAM_PACKAGE_NAME);
        share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

        final Intent chooserIntent = Intent.createChooser(share, "Share to");
        activity.startActivityForResult(chooserIntent, INSTAGRAM_REQUEST_CODE);
        // TODO: Delete the generated image somehow
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

A possibility to delete the image after sharing (which is not tracked yet as far as i have seen) would be to use: contentResolver.delete(savedImageURI, null, null);

Do you have any suggestions or ideas how we could handle the deletion of the image?

segidev commented 4 years ago

Nevermind, this issue is fixed with this pr #6