MTK9630安卓11设备插入u盘后,系统识别到了/storage/A804-B928并且映射挂载到/mnt/media_rw/A804-B928的,但在拔掉u盘的时候出现了/storage/A804-B928路ing被卸载了,/mnt/media_rw/A804-B928没有被卸载掉,导致下一次插入u盘会提示“cutils : Failed to chown(/mnt/media_rw/A804-B928, 0, 0): Operation not permitted”,并且u盘
时间: 2023-06-28 11:15:55 浏览: 77
无法正常挂载。这可能是由于某些进程或应用程序仍在使用U盘导致的。在拔掉U盘前,应该先确保所有使用U盘的进程或应用程序已经关闭或卸载,然后再安全地拔掉U盘。
如果出现这种情况,可以尝试手动卸载/mnt/media_rw/A804-B928挂载点,以确保下一次插入U盘时能够正常挂载。可以通过以下命令来卸载挂载点:
```
$ umount /mnt/media_rw/A804-B928
```
如果在卸载挂载点时提示“Operation not permitted”错误,则需要使用root权限或者使用su命令来提升权限。例如:
```
$ su
$ umount /mnt/media_rw/A804-B928
```
注意:使用su命令需要先在设备上开启root权限或者进行相应的授权操作。同时,手动卸载挂载点可能会导致数据丢失或其他问题,所以在进行操作前应该先备份重要数据。
相关问题
我现在在分析一个android系统问题,把u盘插入到安卓设备里面,系统给予的挂载路径是/mnt/media_rw/A804-B928 ,拔掉u盘后/mnt/media_rw/A804-B928路径没有被成功卸载,导致下次继续插入u盘后就不能挂载成功
这个问题可能是由于系统没有正确卸载挂载点导致的。您可以尝试使用以下步骤来手动卸载挂载点:
1. 查看当前系统中已经挂载的设备:
```
$ mount
```
2. 找到挂载点 `/mnt/media_rw/A804-B928` 对应的设备,记录设备名称,例如 `/dev/sda1`。
3. 使用 `umount` 命令手动卸载挂载点:
```
$ umount /mnt/media_rw/A804-B928
```
4. 如果卸载不成功,可能是因为当前路径下有其他进程正在使用该挂载点,您可以使用 `fuser` 命令查找并杀掉相关进程:
```
$ fuser -km /mnt/media_rw/A804-B928
```
5. 再次尝试使用 `umount` 命令卸载挂载点。
卸载成功后,您可以再次插入 U 盘,系统应该能够成功挂载并分配新的挂载路径。
在Android11设备上,比如u盘的挂载路径/storage/A804-B928下有一个db.apk,如何实现在接受到ACTION_MEDIA_MOUNTED广播后把这个apk复制到DCIM目录下
在 Android 11 设备上,应用程序无法直接访问外部存储设备的根目录,因此在应用程序中直接访问 u 盘可能会出现卸载 u 盘失败的问题。为了避免这个问题,可以使用 Storage Access Framework(SAF)来访问 u 盘中的文件并将其复制到应用程序可以访问的目录中。具体实现步骤如下:
1. 在 `ACTION_MEDIA_MOUNTED` 广播处理程序中启动一个服务,用于将 u 盘中的 db.apk 复制到 DCIM 目录中。
2. 在服务中使用 SAF 访问 u 盘中的 db.apk 文件,具体可以使用 `Intent.ACTION_OPEN_DOCUMENT` 操作打开 SAF 选择器,并让用户选择 u 盘中的 db.apk 文件。
3. 选择 db.apk 文件后,可以使用 `DocumentFile` 类来访问该文件并将其复制到 DCIM 目录中,具体可以使用 `ContentResolver` 和 `DocumentFile.createFile` 方法来创建文件并将 u 盘中的 db.apk 内容写入到该文件中。
4. 复制完成后,可以发送一个广播通知系统图库进行扫描,以便能够在相册中看到该文件。
具体实现代码如下:
```
public class MyMediaReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_MEDIA_MOUNTED.equals(action)) {
Uri uri = intent.getData();
if (uri != null) {
String path = uri.getPath();
if (path != null) {
Intent copyIntent = new Intent(context, CopyService.class);
copyIntent.putExtra("source", path + "/db.apk");
context.startService(copyIntent);
}
}
}
}
}
public class CopyService extends Service {
private static final String TAG = "CopyService";
private static final String DESTINATION_DIR = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String source = intent.getStringExtra("source");
if (source != null) {
copyFile(source);
}
return super.onStartCommand(intent, flags, startId);
}
private void copyFile(String source) {
try {
ContentResolver resolver = getContentResolver();
Uri sourceUri = Uri.parse("content://com.android.externalstorage.documents/tree/" + source.split("/")[1] + "/document/" + source.replaceFirst(".*?/", ""));
DocumentFile sourceFile = DocumentFile.fromSingleUri(this, sourceUri);
InputStream inputStream = resolver.openInputStream(sourceFile.getUri());
String destPath = DESTINATION_DIR + "/db.apk";
OutputStream outputStream = new FileOutputStream(destPath);
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + destPath)));
} catch (Exception e) {
Log.e(TAG, "Error copying file", e);
}
stopSelf();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
```
在广播处理程序中启动了一个服务 `CopyService`,并将 `ACTION_MEDIA_MOUNTED` 广播中的 u 盘路径传递给该服务。在服务中使用 SAF 访问 u 盘中的 db.apk 文件,并将其复制到 DCIM 目录中。复制完成后,发送一个广播通知系统图库进行扫描。
需要注意的是,Android 11 以后需要在应用程序的 `AndroidManifest.xml` 文件中添加以下权限:
```
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
```
同时还需要在 `AndroidManifest.xml` 文件中声明 `MyMediaReceiver` 和 `CopyService` 类:
```
<receiver android:name=".MyMediaReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<data android:scheme="file" />
</intent-filter>
</receiver>
<service android:name=".CopyService" />
```
最后需要注意的是,将文件复制到 DCIM 目录中可能会影响到用户的相册体验,因此应该根据实际需求选择合适的目录进行文件复制。