最主要的方法
/**
* @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(