在Android中分享Instagram的意图

时间:2013-04-30 10:01:55

标签: android instagram

其实我想通过意图在Instagram上分享图片。

I found this solution for images saved on SD card但我想对网站上的图片(链接)做同样的事情。

我试过

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);

但它不起作用。

修改

当我开始上述意图时,它打开我已安装的Instagram应用程序,它立即完成Instagram并且Toast消息“无法下载文件”

实际上它并不分别解析链接和图像。应该是什么问题?

2 个答案:

答案 0 :(得分:2)

您应该使用本地路径来存档

例如:“file:///path/to/file/image.png”。

请注意,在路径中包含“file”非常重要,如果没有此部分,它也可以显示相同的Toast。

答案 1 :(得分:0)

首先,您需要从该网址下载文件。你可以参考这段代码从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);