问剑孤鸣 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 MATLAB yalmip 可转移负荷的简单建模出错,如何解决?
  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?