andrid获取缓存目录返回null
/**
* 根据传入的filename获取硬盘缓存的路径地址
*
* @param context
* @param filename
* @return
*/
public static File getDiskCacheDir(Context context, String filename) {
boolean externalStorageAvailable = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
String cachePath;
if (externalStorageAvailable) {
cachePath = context.getExternalCacheDir().getPath();
} else {
cachePath = context.getCacheDir().getPath();
}
return new File(cachePath + File.separator + filename);
}
执行以上获取缓存目录的代码,在少部分手机上返回null,想请大家帮忙解决