Android11录音出错:
错误分析:
java.io.FileNotFoundException: /storage/emulated/0/noah/audio/audio1658560430443.aac: open failed: EPERM (Operation not permitted)
Android 11 获取存储路径错误 android.system.ErrnoException: open failed: EPERM (Operation not permitted),Android11 不能获取sdcard通用空间路径。
private String getSavePath() {
String path;
if (Build.VERSION.SDK_INT > 29) {
path = mContext.getExternalFilesDir(null).getAbsolutePath() + "/app/audio/";
} else {
path = Environment.getExternalStorageDirectory().getPath() + "/app/audio/";
}
return path;
}
获取的空间路径为 Android/data/XXXX(应用包名)/log
Path 转Uri
public static Uri toUri(Context context,String filePath) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return FileProvider.getUriForFile(context, context.getApplicationInfo().packageName + ".fileprovider", new File(filePath));
}
return Uri.fromFile(new File(filePath));
}