大家都知道Android 版本越高存储数据要求越严格,Android 10以上,要想做到存储数据,并且实现能读取,上传下载。直接这样存储。如下代码
public String getSavePath(){ String ALBUM_PATH = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){ ALBUM_PATH = mContext.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)+"/daylog/"; }else { boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); if (sdCardExist) { ALBUM_PATH = Environment.getExternalStorageDirectory() + File.separator+ mContext.getPackageName()+"/daylog/"; }else{ ALBUM_PATH = mContext.getCacheDir().toString() + File.separator+ mContext.getPackageName()+"/daylog/"; } } return ALBUM_PATH; }
?