方法一:
可以在Androidmainfest 里面的application添加
android:requestLegacyExternalStorage="true"
使用原来的存储方式获取路径:
Environment.getExternalStorageDirectory()
方法二:
public String getPath(Context context) {
File dir = null;
boolean state = Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED );
if (state) {
if (Build.VERSION.SDK_INT >= 29) {
//Android10之后
dir = context.getExternalFilesDir( null );
} else {
dir = Environment.getExternalStorageDirectory();
}
} else {
dir = Environment.getRootDirectory();
}
return dir.toString();
}