android - 我可以使用 ACTION_VIEW 查看我下载的 JPG 吗?

标签 android

我在我的 Android 应用程序中尝试查看使用 ACTION_VIEW 下载的 JPG 文件时遇到了麻烦。我可以验证该文件是否存在并且大小是否正确。我可以从模拟器中提取文件并在我的电脑上打开它,所以我知道 JPG 没有损坏。我也试过 View image in ACTION_VIEW intent? 中的代码.

我的代码如下:

// 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)

对这里发生的事情有什么想法吗?

最佳答案

据我查看平台源代码可以看出,您在 URI 中传递了一个不存在的文件路径。

downloadsDirectoryPath 的值是多少?打赌你 15 个代表点,它不完全合格......

关于android - 我可以使用 ACTION_VIEW 查看我下载的 JPG 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4791097/

相关文章:

Android 推送通知状态图标问题

android - TextInputLayout.setError() 清除错误后留下空白空间

android - 在 Android 中从 Facebook 请求检索电子邮件和位置时出错

java - Android - 在 MapView 上叠加绘制路径

Android Lollipop BLE 外设 : calling BluetoothLeAdvertiser. stopAdvertising(AdvertiseCallback) 从连接的中央断开

android - 将对象列表从一个 Activity 传递到android中的另一个 Activity

android - 测试房间迁移时身份哈希检查失败

android - Haxe 和 Kivy 的优缺点

android - 大内存块没有被垃圾收集

android - 如何在android中解析不区分大小写的查询搜索?