gpt4 book ai didi

java - 使用文件路径在图库中打开图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:50:05 25 4
gpt4 key购买 nike

我的数据库中存储了一个图像文件路径。现在使用它我想在我的画廊中打开 SD 卡中的图像。我怎样才能做到这一点。我已经看到 Uri 的方法并使用了这个方法,但是我收到了错误

File file = new File(filename);
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setType("image/*");
startActivity(intent); /** replace with your own uri */

如何解决,

04-20 08:42:23.516: E/AndroidRuntime(16815): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/My%20App/image_umxto_1.jpg }

最好的问候

最佳答案

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(filename)), "image/*");
startActivity(intent);

使用此代码并告诉我

关于java - 使用文件路径在图库中打开图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10239897/

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