6

实际上,我想通过意图在 Instagram 中分享图像。

我为保存在 SD 卡上的图像找到了这个解决方案,但我想对现场图像做同样的事情(链接)。

我试过了

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 消息“无法下载文件”

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

4

2 回答 2

2

您应该使用本地文件路径

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

请注意,在路径中包含“文件”非常重要,没有这部分它也可以显示相同的 toast。

于 2013-11-18T09:47:07.293 回答
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);
于 2014-02-11T06:28:18.003 回答