Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram sharing issue: sometimes I get the message "Unable to load image"

I am using a sharing functionality to social application using Intent.

I have a problem with sharing an image in Instagram.

Some times I get the message

Unable to load Image.

Here is my code:

String path="content://media/external/images/media/32872";

Intent shareIntent = new Intent();
shareIntent.setType("image/jpeg");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
shareIntent.setPackage("com.instagram.android");
startActivity(shareIntent);

How do I get rid of this problem?

like image 597
Chirag Parmar Avatar asked Jun 23 '15 12:06

Chirag Parmar


1 Answers

if you have file then use below code to share image,

private void shareIntagramIntent(String path) {
        Intent intent = getActivity().getPackageManager()
                .getLaunchIntentForPackage("com.instagram.android");
        if (intent != null) {
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.setPackage("com.instagram.android");
            try {
                shareIntent.putExtra(Intent.EXTRA_STREAM,
                        Uri.parse("file://" + path));
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            shareIntent.setType("image/jpeg");

            startActivity(shareIntent);
        } else {
            // bring user to the market to download the app.
            // or let them choose an app?
            intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse("market://details?id="
                    + "com.instagram.android"));
            startActivity(intent);
        }
    }
like image 60
NullByte Avatar answered Oct 21 '22 15:10

NullByte