我正在尝试查看我在Android应用程序中使用ACTION_VIEW下载的JPG文件。我可以验证文件是否存在,并且它是正确的大小。我可以从模拟器中拉出文件并在计算机上打开它,所以我知道JPG并未损坏。我也尝试了View image in ACTION_VIEW intent?中的代码。我可以使用ACTION_VIEW查看我已下载的JPG吗?
我的代码如下:
// start intent to view the file
String filename = "test.jpg"
String downloadsDirectoryPath = getFilesDir().getPath() + "/downloads";
File file = new File(downloadsDirectoryPath + "/" + filename);
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(file), "image/*");
startActivity(i);
这似乎应该是简单的,但每当我运行上面的代码,我得到
ERROR/UriImage(336): got exception decoding bitmap
ERROR/UriImage(336): java.lang.NullPointerException
ERROR/UriImage(336): at com.android.camera.Util.makeInputStream(Util.java:336)
ERROR/UriImage(336): at com.android.camera.Util.makeBitmap(Util.java:307)
ERROR/UriImage(336): at com.android.camera.Util.makeBitmap(Util.java:299)
ERROR/UriImage(336): at com.android.camera.gallery.UriImage.fullSizeBitmap(UriImage.java:94)
ERROR/UriImage(336): at com.android.camera.gallery.UriImage.fullSizeBitmap(UriImage.java:86)
ERROR/UriImage(336): at com.android.camera.gallery.UriImage.thumbBitmap(UriImage.java:120)
ERROR/UriImage(336): at com.android.camera.ImageGetter$ImageGetterRunnable.executeRequest(ImageGetter.java:173)
ERROR/UriImage(336): at com.android.camera.ImageGetter$ImageGetterRunnable.run(ImageGetter.java:149)
ERROR/UriImage(336): at java.lang.Thread.run(Thread.java:1096)
什么是怎么回事任何想法?
你加android.permission.INTERNET对你的AndroidManifest.xml – 2011-01-25 08:35:06
感谢您的评论。是的,我在清单中有这个。我实际上可以验证该文件是否存在于仿真器中。我弄清楚我的问题与权限有关,而不是与jpg文件相关。请参阅我对其他答案的回答以获得解释。 – 2011-01-25 19:01:16