Android - 显示来自可绘制资源的图像

标签 android image android-intent resources

我是 Android 应用的新手,我正在从事一个由我的 friend 发起的项目。下面的代码来自一个类,该类加载一个 View ,该 View 有一个小图像,周围有一些文本。

当我点击缩略图时,我希望图像全屏显示(在标准的 Android 图像查看器上)。 我尝试了几种不同的解决方案,但都没有奏效。

此示例抛出以下异常:

E/AndroidRuntime(13768): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.app.mid/2130837533 typ=image/png }
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_n1);

    ImageView img = (ImageView) findViewById(imageResource);

    img.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent();
            intent.setAction(android.content.Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse("android.resource://com.app.mid/" + R.drawable.p_page_11_image_0001), "image/png");
            startActivity(intent);              
        }
    });        
}

图像位于可绘制文件夹 (..\res\drawable-xhdpi) 内。我正在使用 Eclipse ADT,并将其配置为在我的 Galaxy Nexus 上运行。

同样,我尝试了几种解决方案,但都没有成功。有什么想法吗? 谢谢

最佳答案

尝试使用 Intent.ACTION_VIEW 而不是 android.content.Intent.ACTION_VIEW

Intent i = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(yourUri, "image/png");
startActivity(intent);

关于Android - 显示来自可绘制资源的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15282671/

相关文章:

android - 自定义对话框需要时间才能显示

android - 无法添加支持库 v7 AppCompat

android - 多个dex文件定义Landroid/support/design/widget/CoordinatorLayout$LayoutParams

php - 使用android从WAMP服务器存储和检索图像

html - 主图文本属性

安卓 Intent ACTION_IMAGE_CAPTURE

android - 添加 Firebase In-App Messaging 依赖项会导致 DexArchiveMergerException

facebook - 如何在 Facebook 中使用动画图片?

android - 找不到处理 Intent act=android.intent.action.OPEN_DOCUMENT 的 Activity

android - 为什么 getStringExtra 没有给出正确的输出?