【问题标题】:Android: Is it possible to share an image to Instagram, stored in Google Cloud Storage?Android:是否可以将存储在 Google Cloud Storage 中的图像分享到 Instagram?
【发布时间】:2018-11-28 22:53:35
【问题描述】:

我有一张图片存储在 Google Cloud Storage 中。我想允许我的应用程序的用户将其分享到 Instagram。因此,我在 Storage 中获得了对它的引用,然后我获得了下载 URL(一个 URI 对象)并将其放入我用来打开 Instagram 的意图的额外数据中。

但 Instagram 表示“图片无法加载”。我认为这是因为 URI 指向 Cloud Storage 返回的 Web URL,而不是指向本地文件的 URI。不? 有什么方法可以让我的程序使用指向 Cloud Storage 返回的 Web URL 的 URI 运行?

来源

代码如下:

final Intent intent_share = new Intent(Intent.ACTION_SEND);
intent_share.setType("image/*");

FirebaseStorage firebase_storage = new SetupFirebaseStorage().getFirebaseStorage();
StorageReference storage_reference = firebase_storage.getReference();
storage_reference.child(image_uuid).getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
    @Override
    public void onSuccess(Uri uri) {
        intent_share.putExtra(Intent.EXTRA_STREAM, uri);
        activity.startActivity(Intent.createChooser(intent_share, "Share to"));
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        Toast.makeText(getContext(), "An error occurred during the publication image's URL retrieving.", Toast.LENGTH_LONG).show();
    }
});

【问题讨论】:

    标签: android google-cloud-storage instagram share firebase-storage


    【解决方案1】:

    official Instagram's documentation for Android developers 中所述,Intent 必须具有指向设备中的媒体路径的 URI。

    但是,正如您所说,您在 Intent 中放入了下载 URL(查看方法 getDownloadUrl 的文档),而不是指向本地设备中图像的 URI。事实上,图像甚至还没有在你的手机中。您需要做的是使用您获得的 URL 下载图像,然后将媒体的 URI 放入意图中。

    【讨论】:

    • 也许他们写“在设备上”而不考虑图像存储在其他地方的可能性,例如......在远程设备中(在我的上下文中,谷歌的云存储服务器)?真的没有办法以这种方式运行我的程序,即无需将 iamge 临时存储在我用户的手机上吗?这将是多一步,不必要的,我将不得不处理它的“临时”方面,这很无聊。
    • 尽管我对此并不确定,但我很确定设备指的是手机。此外,如果 Instagram 应用程序没有正确的凭据,他们如何访问您自己的 Google Cloud Storage,您在 Intent 中为应用程序提供的只是文件路径。 @JarsOfJam-调度器
    • 另外,你可以做以下实验:你是否使用设备中的Google相册将照片存储在云端?您可以在云中的一张照片中单击“分享”按钮,然后选择在 Instagram 中分享。一旦您这样做,共享就不会立即进行。在 Instagram 打开之前,您可以看到一个加载器,上面写着“正在下载图片”。
    猜你喜欢
    • 2019-07-29
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2018-05-23
    • 2017-04-11
    • 1970-01-01
    相关资源
    最近更新 更多