Android格式化外部设备如USB等

本文介绍如何在Android源码环境中编译并格式化外部设备如USB和SDcard。强调只能在源码中编译,Eclipse环境下会报错。详细步骤包括源码目录设置、SDK编译、环境配置、项目编译及APK位置查找。
摘要由CSDN通过智能技术生成

最主要的方法

    /**
     * @Description 格式化
     * @param path 路径
     * @return true success ;false failure
     */
    public boolean formatMedia(final String path) {
        IMountService mountService =  getMountService();
        int result = 0;
        try {
            //当卸载完sdcard后才能格式化sdcard - sdcard can be formatted only after the sdcard is unloaded
            mountService.unmountVolume(path, true, false);
            //给sdcard卸载的时间不能超过5s,超过5s后iMountService.formatVolume()不起作用。
            Thread.sleep(4 * 1000);
            result = mountService.formatVolume(path); //这步就是格式化
            Log.d(TAG, "---------volume's path is " + path + "------format success ? " + result);
            if (result == 0) { //如果成功卸载
                Thread.sleep(4 * 1000);
                int resultMount = mountService.mountVolume(path); //挂载回去
                Log.d(TAG, "---------result_mount " + resultMount); //挂载结果
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if (result != 0) {
            return true;
        }
        return false;
    }

    /**
     * @Description 得到IMountService
     * @return IMountService
     */
    public synchronized IMountService getMountService() {
        if (mMountService == null) {
            IBinder iBinder = ServiceManager.getService(
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值