zoukankan      html  css  js  c++  java
  • android通过代码来实现卸载SD卡(转载)

    在一些时候,需要卸载SD卡来测试东西,但眼前的没有合适的手机让你拔掉SD卡,那么可以通过以下代买来卸载SD卡。

    代码是

    private void doUnmount() {
    
            IMountService mountService = getMountService();
    
            String extStoragePath = Environment.getExternalStorageDirectory().toString();
    
            try {
    
                mountService.unmountVolume(extStoragePath, true, true);
    
            } catch (RemoteException e) {
    
     
    
                Log.i("TT","unmount failed.");
    
            }
    
        }
    
            
    
            
    
        private synchronized IMountService getMountService() {
    
        IMountService mMountService = null;
    
           if (mMountService == null) {
    
               IBinder service = ServiceManager.getService("mount");
    
               if (service != null) {
    
                   mMountService = IMountService.Stub.asInterface(service);
    
               } else {
    
                   Log.e("TT", "Can't get mount service");
    
               }
    
           }
    
           return mMountService;
    
        } 

    但这会发现在android4.1中没有相关的接口。所以必须导入framework_intermediates下面的classes jar包就OK了。

  • 相关阅读:
    010-你觉得单元测试可行吗
    跳台阶
    斐波那契数列
    旋转数组的最小数字
    用两个栈实现队列
    重建二叉树
    从尾到头打印链表
    替换空格
    二维数组中的查找
    Best Time to Buy and Sell Stock III
  • 原文地址:https://www.cnblogs.com/chlips/p/2703555.html
Copyright © 2011-2022 走看看