gpt4 book ai didi

java - 将 Firebase 图像 URI 共享给其他应用程序时共享失败?

转载 作者:行者123 更新时间:2023-11-29 04:16:34 25 4
gpt4 key购买 nike

将图像 URI 共享到其他共享时失败。所以我想要一个关于如何使用蓝牙、whatsapp 等将我的应用程序图像共享到其他应用程序的解决方案。

这是我的代码:

ArrayList <Uri> imageUri = new ArrayList<>();

for (int i = 0; i < urimodel.size(); i++) {
Uri model_uri = urimodel.get(i); //getting uri from here

imageUri.add(model_uri);

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
context.startActivity(Intent.createChooser(shareIntent, "Share images to.."));
}

最佳答案

我的建议是先保存你想分享的图片然后传递uri

引用:Share Image with Other Apps

尝试这样的事情

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("image/*");

// For a file in shared storage. For data in private storage, use a ContentProvider.
Uri uri = Uri.fromFile(getFileStreamPath(pathToImage));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(shareIntent)

如果您想通过 Assets 文件夹共享它,则必须使用 ContentProvider。请参阅此答案以了解如何执行此操作:

https://stackoverflow.com/a/7177103/1369222

OR

在 Android Manifest 中添加 File Provider

<provider
android:name="android.support.v4.content.FileProvider"
android:grantUriPermissions="true"
android:exported="false"
android:authorities="${applicationId}">

<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths"/>

file_provider_paths.xml

<paths>
<cache-path name="cache" path="/" />
<files-path name=”files” path=”/” />
</paths>

看到那个How to use support FileProvider for sharing content to other apps?

关于java - 将 Firebase 图像 URI 共享给其他应用程序时共享失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52023974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com