Android 下通过反射调用加载/卸载(mount/unmount) 外置SD卡


  308人阅读  评论(0)  收藏  举报

看别人的帖子,最后写出来,原帖没提供必要的几个文件,我这里找到了给大家找全了。


1.在你的工程src目录下创建Android.os.storage包,导入我上传的几个源文件;从这里下载:http://download.csdn.net/detail/wangxinxxx/8269731

2.导入以下代码,调用mount()、unMount()就行了


[java]  view plain  copy
  1. package cn.steven.timeswitch;  
  2.   
  3. import android.os.IBinder;  
  4. import android.os.RemoteException;  
  5. import android.os.storage.*;  
  6. import android.util.Log;  
  7.   
  8. import java.lang.reflect.Method;  
  9.   
  10. /** 
  11.  * Created by momobile on 2014-12-17. 
  12.  */  
  13. public class Utils {  
  14.     static IMountService iMountService;  
  15.   
  16.     static {  
  17.         Log.v("DWXD", android.os.Environment.getExternalStorageDirectory().toString());  
  18.         try {  
  19.             Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);  
  20.             IBinder binder = (IBinder) method.invoke(null"mount");  
  21.             iMountService = IMountService.Stub.asInterface(binder);  
  22.         } catch (Exception e) {  
  23.             e.printStackTrace();  
  24.         }  
  25.     }  
  26.   
  27.     public Utils() {  
  28.     }  
  29.   
  30.     static void unMount() {  
  31.         try {  
  32.             iMountService.unmountVolume(android.os.Environment.getExternalStorageDirectory().toString(), truetrue);  
  33.         } catch (RemoteException e) {  
  34.             e.printStackTrace();  
  35.         }  
  36.     }  
  37.   
  38.     static void mount(){  
  39.         try {  
  40.             iMountService.mountVolume(android.os.Environment.getExternalStorageDirectory().toString());  
  41.         } catch (Exception e) {  
  42.             e.printStackTrace();  
  43.         }  
  44.     }  
  45. }  


出处:

http://blog.csdn.net/a231930/article/details/7587880

http://blog.csdn.net/dahuaishu2010_/article/details/14127445

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值