我正在嘗試查看我在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