0

我有一个带有缩略图的应用程序,当用户触摸拇指时,我想全屏打开整个图像。我尝试在默认图库应用中打开图像,但它不适用于所有设备。

这是片段:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url_of_the_remote_image_here));
intent.setType("image/jpg");
startActivity(intent);

在运行 4.1 的 Nexus S 上,我得到:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW typ=image/jpg }

我尝试了几段代码,许多都在浏览器中打开了图像。因为所有安卓设备都有默认图库,难道不能用它打开远程图片吗?

4

1 回答 1

0

你永远不应该假设有活动来处理你的互联网,所以总是startActivity()try/catch. 我会使用正确的 mime 类型image/jpeg,但实际上我会用更通用的方式替换它image/*

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url_of_the_remote_image_here));
intent.setType("image/*");
try {
   startActivity(intent);
} catch( Exception e ) {
   e.printStatckTrace();
}
于 2013-06-27T14:49:40.480 回答