我需要打开一个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/