vstirbu / InstagramPlugin

Instagram plugin for PhoneGap/Cordova
MIT License
120 stars 78 forks source link

Attempts to share file using file:// (exposed beyond app through ClipData.Item.getUri()) #75

Closed mpk2 closed 7 years ago

mpk2 commented 7 years ago

With the current setup, sharing fails on Android N because of restrictions on use of the file protocol. Here is a description of the change.

In order to resolve the problem, I had to make changes to share in CDVInstagramPlugin.java below

private void share(String imageString, String captionString) {
        ...
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("image/*");
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
            shareIntent.putExtra(Intent.EXTRA_TEXT, captionString);
            shareIntent.setPackage("com.instagram.android");

            this.cordova.startActivityForResult((CordovaPlugin) this, Intent.createChooser(shareIntent, "Share to"), 12345);

       ...
    }

You'll notice that this is very similar to the official Instagram example (https://www.instagram.com/developer/mobile-sharing/android-intents/).

mpk2 commented 7 years ago

Added PR #76

vstirbu commented 7 years ago

merged