【问题标题】:Share intent for instagram in Android在 Android 中分享 instagram 的意图
【发布时间】:2013-04-30 10:01:54
【问题描述】:

其实我想通过intent在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 消息“无法下载文件”

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

【问题讨论】:

  • 定义不工作。任何错误信息?
  • “无法下载文件”。消息来自 Instagram 应用
  • 这里有同样的问题。试图找出图像是否存在。

标签: android instagram


【解决方案1】:

你应该使用本地文件路径

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

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

【讨论】:

  • 在照片共享中仍然遇到同样的问题。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多