有没有办法在android中检测到microSD卡?我知道Environment类提供了外部存储的详细信息。但它只是给出了内置SD卡的详细信息。有没有附近的路?
发布于 2011-08-23 14:07:18
您可以使用isExternalStorageEmulated()来确定当前的“外部”存储实际上是真正的外部存储,还是仅仅是内部存储的一部分。如果它是真实的,那么你应该得到可移动卡的属性。
发布于 2011-08-23 15:14:50
试试这个:
boolean canSaveExternal = false;
String storageState = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(storageState))
canSaveExternal = true;
else
canSaveExternal = false;发布于 2017-03-21 00:21:37
Environment.getExternalStorageState()和Environment.getExternalStorageDirectory()将提供内置的SD卡,现在几乎所有的安卓设备上都有SD卡。
获得“真正的”外部SD卡(或U盘)的两种方法。
context.getSystemService(Context.STORAGE_SERVICE);静态字符串方法(上下文上下文){ Class.forName("android.os.storage.StorageVolume");mStorageManager = ( StorageManager ) Class storageVolumeClazz = null;mStorageManager.getClass().getMethod("getVolumeList");{StorageManager=Class.forName(“android.os.storage.StorageVolume”);mStorageManager=StorageManager Class<?> storageVolumeClazz = storageVolumeClazz.getMethod(" getPath ");storageVolumeClazz isRemovable = storageVolumeClazz.getMethod("isRemovable");Object result = getVolumeList.invoke(mStorageManager);final int length = Array.getLength(result);for (int i= 0;i< length;i++) { Object storageVolumeElement = Array.get(result,i);String path = (String) getPath.invoke(storageVolumeElement);boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement);if (removable) {返回路径;} catch (ClassNotFoundException e) { e.printStackTrace();} catch (InvocationTargetException e) { e.printStackTrace();} catch (NoSuchMethodException e) { e.printStackTrace();} catch (IllegalAccessException e) { e.printStackTrace();}返回null;}装载存储时,
@Override public void onReceive(Context context,Intent intent) { if (intent != null) { if (Intent.ACTION_MEDIA_MOUNTED.equals(intent.getAction())) {onReceive= intent.getDataString().replace("file://",“);}
https://stackoverflow.com/questions/7156814
复制相似问题