如下所示:
public static boolean isSdcardExists(Context context) {
StorageManager storageManager = StorageManager.from(context.getApplicationContext());
List volumes = storageManager.getVolumes();
for (VolumeInfo volInfo : volumes) {
DiskInfo diskInfo = volInfo.getDisk();
if (diskInfo != null && diskInfo.isSd()) {
String sdcardState = volInfo.getEnvironmentForState(volInfo.getState());
if (Environment.MEDIA_MOUNTED.equals(sdcardState)) {
return true;
}
}
}
return false;
}
public static int isudiskExists(Context context) {
int num = 0;
StorageManager storageManager = StorageManager.from(context.getApplicationContext());
List volumes = storageManager.getVolumes();
for (VolumeInfo volInfo : volumes) {
DiskInfo diskInfo = volInfo.getDisk();
if (diskInfo != null && diskInfo.isUsb()) {
String sdcardState = volInfo.getEnvironmentForState(volInfo.getState());
if (Environment.MEDIA_MOUNTED.equals(sdcardState)) {
num++;
}
}
}
return num;
}
以上这篇Android 6.0区别U盘和SD卡设备的方法详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。