Android:是否可以将存储在 Google 云存储中的图像分享到 Instagram?

Android: Is it possible to share an image to Instagram, stored in Google Cloud Storage?

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

但是 Instagram 说 "image is impossible to load"。我认为这是因为 URI 指向由 Cloud Storage 返回的 Web URL 而不是指向本地文件的 URI。不? 有什么方法可以使我的程序使用云存储返回的指向 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();
    }
});

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

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