踩坑记录(4)-DiskLruCache需要权限
来源:互联网 发布:narcissu 知乎 编辑:程序博客网 时间:2024/06/07 11:05
Volley的ImageLoader里要自己写个缓存,于是上网看了几篇文章,感觉都差不多,就照抄下来,一次成功(android 4.4),效果良好。
后来换了个android 4.2的机器测试就出错了,在下图位置报了一个空指针(其实写了什么并不重要)
最后在
http://stackoverflow.com/questions/14391314/android-getexternalcachedir-returns-null
发现答案。
Despite the somewhat cryptic NullPointerException that gets thrown the actual issues is that my application did not have WRITE_EXTERNAL permission, so the system was rejecting my attempt to use the ExternalDir for caching. Unfortunately this was happening at a low enough level in the code used in Displaying Bitmaps Effeciently that the Exception does not indicate SecurityException as it normally would if one were trying to write to the SD card without the proper permission.
To fix simply add this:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
to your manifest.
感觉好气。。。然后看了下评论
On android 4.4+ this permission is no longer required for cache purpose You can use this permission with the maxSdkVersion paremeter:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
-
And on some lollipop builds this is broken, so I suggest removing the max sdk … Silly I know
另:
写了一个获取网易云音乐歌曲封面的app,已经能看出形状了,
https://github.com/mmga/CloudCover
- 踩坑记录(4)-DiskLruCache需要权限
- DiskLruCache
- DiskLruCache
- disklrucache
- DiskLruCache
- DiskLruCache
- DiskLruCache
- DiskLruCache
- DiskLruCache
- disklrucache
- DiskLruCache
- Android WiFi 权限、广播、连接、踩坑相关记录
- android DiskLruCache看源码并记录思路日志
- 记录:AFN第三方框架,上传文件的子文件夹也需要打开读写权限。
- Android记录手机屏幕操作并进行回放(需要root权限)
- 需要时提升权限
- 生活需要记录
- 成长中需要记录
- Spring定时任务的几种实现
- 新阶乘问题,有两个数a,b(a>=b),求a到b之间所有数的阶乘之和;数据有多组.
- 马化腾内部讲座:我们希望的产品经理是从技术晋升而来的
- 对List里的对象元素进行排序
- LeetCode Product of Array Except Self
- 踩坑记录(4)-DiskLruCache需要权限
- iOS 获得汉字拼音首字母
- c语言输出的%
- 使用supervisor提高nodejs调试效率
- hpuoj 1136: HH生病了 (递推)
- 不同浏览器对URI以及queryString是如何编码的?
- nyoj--1170--最大的数(数学技巧)
- c++ STL 算法库用法
- Android 屏幕适配