android 12 U盘 /mnt/media
•
移动开发
现象
storage下可读取,但/mnt/media_rw不可读取
/mnt/media_rw/A009-1B4F/rk3568_s-ota-20230704.zip (Permission Denied)
解决方法
把/mnt/media_rw/ 替换为 /storage


1.在解析ota升级包时,将 /mnt/media_rw/ 替换为 /storage
if (Build.VERSION.SDK_INT >= 30) {
if (mImageFilePath.startsWith("/data/media")) {
tempPath = mImageFilePath.replace("/data/media", "/storage/emulated");
} else if (mImageFilePath.startsWith("/mnt/media_rw")) {
tempPath = mImageFilePath.replace("/mnt/media_rw", "/storage");
}
}
2.真正执行升级逻辑时,将 /storage 再替换回 /mnt/media_rw/
if (Build.VERSION.SDK_INT >= 30) { // Build.VERSION_CODES.R
Log.d(TAG, "installPackage SDK version >= Build.VERSION_CODES.R,should convert update file path.");
if (parsedUpdate.mUrl.startsWith("file:///storage/emulated/0")) {
convertPath = parsedUpdate.mUrl.replace("/storage/emulated/0", "/data/media/0");
Log.d(TAG, "startsWith(\"file:///storage/emulated/0\")");
} else if (parsedUpdate.mUrl.startsWith("file:///storage")) {
convertPath = parsedUpdate.mUrl.replace("/storage", "/mnt/media_rw");
Log.d(TAG, "startsWith(\"file://storage\")");
}
Log.d(TAG, "installPackage update " + parsedUpdate.mUrl + " to " + convertPath);
}
本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/0fd4dbbe45.html
