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了。

  • 相关阅读:
    MYSQL语法篇之:“建”、“增”
    MYSQL数据库管理系统
    数据库管理系统
    初识数据库
    JDK/JRE/JVM的区别与联系
    计算机语言的发展史
    Java的三大版本
    Java的特性和优势
    初识Java
    补充:DOS命令
  • 原文地址:https://www.cnblogs.com/chlips/p/2703555.html
Copyright © 2011-2022 走看看