看别人的帖子,最后写出来,原帖没提供必要的几个文件,我这里找到了给大家找全了。
1.在你的工程src目录下创建Android.os.storage包,导入我上传的几个源文件;从这里下载:http://download.csdn.net/detail/wangxinxxx/8269731
2.导入以下代码,调用mount()、unMount()就行了
- package cn.steven.timeswitch;
-
- import android.os.IBinder;
- import android.os.RemoteException;
- import android.os.storage.*;
- import android.util.Log;
-
- import java.lang.reflect.Method;
-
-
-
-
- public class Utils {
- static IMountService iMountService;
-
- static {
- Log.v("DWXD", android.os.Environment.getExternalStorageDirectory().toString());
- try {
- Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);
- IBinder binder = (IBinder) method.invoke(null, "mount");
- iMountService = IMountService.Stub.asInterface(binder);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public Utils() {
- }
-
- static void unMount() {
- try {
- iMountService.unmountVolume(android.os.Environment.getExternalStorageDirectory().toString(), true, true);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
-
- static void mount(){
- try {
- iMountService.mountVolume(android.os.Environment.getExternalStorageDirectory().toString());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
出处:
http://blog.csdn.net/a231930/article/details/7587880
http://blog.csdn.net/dahuaishu2010_/article/details/14127445