android - 如何在android中获取图像资源的uri

标签 android uri

我需要打开一个intent来查看图片,如下:

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("@drawable/sample_1.jpg");
intent.setData(uri);
startActivity(intent);

问题是 Uri uri = Uri.parse("@drawable/sample_1.jpg"); 不正确。

最佳答案

格式为:

"android.resource://[package]/[res id]"

[package] 是你的包名

[res id] 是资源 ID 的 ,例如R.drawable.sample_1

要将其拼接在一起,请使用

Uri path = Uri.parse("android.resource://your.package.name/"+ R.drawable.sample_1);

关于android - 如何在android中获取图像资源的uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4896223/

相关文章:

android - 在 Android 中加载大量短裤

ruby-on-rails - 在 Rails 中使用主机和多个路径字符串创建 URL

android - 如何从android 10中的位图获取uri

android - 如何在 Android Studio 中使用 Robotium?

java - 将文本中心与给定位置对齐

java - 优雅地杀死 Java 在 Android 中打开的进程

java - Jsoup:如何获取图像 src 作为绝对 uri?

javascript - URIencode 和冒号

Android:倾斜移动使 ImageView 内容消失/URI 刷新

android - 随机时间 WIN DEATH : in cocos2d-x