当前位置 : 主页 > 手机开发 > android >

Android 6.0区别U盘和SD卡设备的方法详解

来源:互联网 收集:自由互联 发布时间:2021-06-05
如下所示: public static boolean isSdcardExists(Context context) { StorageManager storageManager = StorageManager.from(context.getApplicationContext()); ListVolumeInfo volumes = storageManager.getVolumes(); for (VolumeInfo volInfo : vo

如下所示:

public static boolean isSdcardExists(Context context) {

  StorageManager storageManager = StorageManager.from(context.getApplicationContext());
  List<VolumeInfo> 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<VolumeInfo> 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卡设备的方法详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持自由互联。

网友评论