Share intent for instagram in android

In fact, I want to share the image on instagram through the intention

I found this solution for images stored on the SD card , but I want to do the same for the image on the site (link)

I tried using

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    shareIntent
            .putExtra(
                    Intent.EXTRA_STREAM,
                    Uri.parse("http://www.alliswell.biz/images/products/art/alliswell_signs/yellowB.jpg"));
    shareIntent.setPackage("com.instagram.android");
    startActivity(shareIntent);

But that does not work. Please, help.

EDIT

When I start with this intention, it opens my installed instagram application, and it immediately finishes the instagram, and the toast message arrives “unable to upload file”

In fact, it does not parse the link and image accordingly. What should be the problem?

+5
source share
2 answers

You must use the local file path

: "file:///path/to/file/image.png".

, "" , .

+2

, URL-. URL:

String imageUrl = "Your_Image_Url";

    if (imageUrl != null && !imageUrl.equals("")) {

        String fileName = generateFileNameFromUrl(imageUrl);

        String imageLocalPath = Environment.getExternalStorageDirectory()+ File.separator+"Your_App_Name"+ fileName;

        if (!new File(imageLocalPath).exists()) {

        ImageDownloadModel imageDownloadModel = new ImageDownloadModel();

        imageDownloadModel.setImageLocalPath(imageLocalPath);

        imageDownloadModel.setImageUrl(imageUrl);

        imageDownloadModels.add(imageDownloadModel);

        }
        ImageLoadAsynkTask imageLoadAsynkTask = new ImageLoadAsynkTask(new ImageDownloadDelegate(), imageDownloadModels, albumDir, activity);
        imageLoadAsynkTask.execute();

uri instagram:

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + imageLocalPath));
shareIntent.setPackage("com.instagram.android");
activity.startActivity(shareIntent);
0

All Articles