Caused by: android.system.ErrnoException: open failed: EPERM (Operation not permitted)

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));
    }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容