问剑孤鸣 2015-10-13 07:43 采纳率: 0%
浏览 3323
已结题

android webview img标签加载图片问题

请教一个问题,我在webview中的img标签中显示图片,显示getCacheDir( )目录下的图片显示不出来,但显示getExternalCacheDir()中的图片就行,路径是都是正确的,这是什么原因?

  • 写回答

2条回答

  • daweibalang717 2015-10-13 08:57
    关注

    getExternalCacheDir() 方法 API 如下:
    File android.content.ContextWrapper.getExternalCacheDir()

    Returns the absolute path to the directory on the primary external filesystem (that is somewhere on Environment.getExternalStorageDirectory() where the application can place cache files it owns. These files are internal to the application, and not typically visible to the user as media.

    This is like getCacheDir() in that these files will be deleted when the application is uninstalled, ①however there are some important differences:
    **
    The platform does not always monitor the space available in external storage, and thus may not automatically delete these files. Currently the only time files here will be deleted by the platform is when running on android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 or later and Environment.isExternalStorageEmulated() returns true. Note that you should be managing the maximum space you will use for these anyway, just like with getCacheDir().
    External files are not always available: they will disappear if the user mounts the external storage on a computer or removes it. See the APIs on android.os.Environment for information in the storage state.
    **②There is no security enforced with these files. For example, any application holding android.Manifest.permission.WRITE_EXTERNAL_STORAGE can write to these files. **

    ①和②你可以看下:
    ①说:以下是与getCacheDir不同点
    ②说: android.Manifest.permission.WRITE_EXTERNAL_STORAGE 只要有权限的应用都具有写权限。
    那可以推导出 谁调用getCacheDir() 谁才能访问。

    而从你的描述来看,你调用的是相机,相对于你的webView 来说是另外一个应用,那么 getCacheDir()是相机去调用存储的,因为不了解你的问题,我大体推算出 路径 是 /data/data/XXXX.camera/cache 那么基于上面的分析,webView 所在的应用是不具有访问 相机 缓存的权限。 而getExternalCacheDir 只要有android.Manifest.permission.WRITE_EXTERNAL_STORAGE 权限的应用都具有写权限

    没能太理解你遇到的问题,以上不知能不能解决你的疑惑

    评论

报告相同问题?

悬赏问题

  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?