如何在Android 4.2中以编程方式卸载USB DRIVE [英] How unmount programmatically USB DRIVE in Android 4.2

查看:295
本文介绍了如何在Android 4.2中以编程方式卸载USB DRIVE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了许多有关此主题的文章,但尚未找到解决方案. 在我的应用程序中,将文件从USB DRIVE复制到平板电脑后,我需要卸载USB DRIVE,这样我就可以安全地将其删除,而无需使用设置"菜单.

I have read many posts on this topic, but I have not found a solution yet. In my application I need to unmount the USB DRIVE after copying files from USB DRIVE to the tablet, so I can safely remove it without using the Settings menu.

现在我正在使用此方法:

Right now I am using this method:

Utility.copyDirectory(file,new File(_CURR_FOLDER));
Process su;
su = Runtime.getRuntime().exec("/system/bin/su");
String cmd = "umount" +
             " " + SDPath + "\n" + "exit\n";
             su.getOutputStream().write(cmd.getBytes());

我在存储设置中得到的是:

What I get in the storage settings is:

总空间0.0 可用0.0

Total space 0.0 Available 0.0

但SD仍已安装.

预先感谢您的帮助.

首次

有人知道如何使用IMountService吗?我读了有关它,也许是解决USB DRIVE卸载问题的正确方法,但是添加classes-full-debug.jar后,我的项目不再编译

Someone know how use IMountService? I read about it, and maybe is the right way to solve the unmount of USB DRIVE, but after adding classes-full-debug.jar my project is no longer compiled

推荐答案

无法完成.许多用户在其中存储所有内容,例如歌曲,视频,照片.不允许应用卸载SD卡,而是使用它们存储数据是一个很好的安全决策.

this cannot be done. Many users store all their content like songs, videos, photos there. it was a good security decision to not allow apps to unmount SD card, but use them to store data.

但是您可以将用户发送给设置并由用户执行,而无需通过代码

but u can send user to setting and user do it , not by code

Intent i = new Intent(android.provider.Settings.ACTION_MEMORY_CARD_SETTINGS);
startActivity(i);

将显示该屏幕...

我认为这会起作用

这篇关于如何在Android 4.2中以编程方式卸载USB DRIVE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆