if(Utils.getPhoneStorage() !=null && Utils.getPhoneStorage().total ==0)
//处于USB模式
Utils.java
public static File getPhoneDirMtk(){
//if(isSDCardReady()){
// return new File("/mnt/sdcard");
//
}else{
//return new File("/mnt/sdcard2");
//}
String path = StorageManagerEx.getInternalStoragePath();
return new File(path);
//return new File("/sdcard");
// } Modify by hyman 20131231
}
public static class PhoneStorageInfo {
public long total;
public long free;
}
public static PhoneStorageInfo getPhoneStorage(){
File pathFile = getPhoneDirMtk();
//StorageManager mStorageManager = (StorageManager)context.getSystemService(Context.STORAGE_SERVICE);
try {
android.os.StatFs statfs = new android.os.StatFs(pathFile.getPath());
long blockSize = statfs.getBlockSize();
long availableBlocks = statfs.getAvailableBlocks();
long blockTotalSize = statfs.getBlockSize();
long totalBlocks = statfs.getBlockCount();
PhoneStorageInfo info = new PhoneStorageInfo();
info.total = blockTotalSize * totalBlocks;
info.free = blockSize * availableBlocks;
return info;
} catch (IllegalArgumentException e) {
}
return null;
}
其中,
getPhoneDirMtk中使用mtk的库函数。 如果不是mtk手机,请换成,
public static File getPhoneDir() {
if (isSDCardReady()) {
return new File("/storage/sdcard1");
} else {
return new File("/storage/sdcard0");
}
}