如何获取已安装的android设备外部存储的列表

在这里,我们正在为android电视盒开发android应用程序。我如何获得已挂载外部存储的列表,例如USB stick, SDCARD and SATA HDD.



慕村225694
浏览 605回答 3
3回答

繁花不似锦

要获取所有可用的外部存储文件夹(包括SD卡),可以使用以下命令:File[] externalStorageFiles=ContextCompat.getExternalFilesDirs(this,null);要转到每个外部存储的“根目录”(这是真正的安装文件夹路径),可以使用我已经完成的以下功能:  /** Given any file/folder inside an sd card, this will return the path of the sd card */  private static String getRootOfInnerSdCardFolder(File file)    {    if(file==null)      return null;    final long totalSpace=file.getTotalSpace();    while(true)      {      final File parentFile=file.getParentFile();      if(parentFile==null||parentFile.getTotalSpace()!=totalSpace)        return file.getAbsolutePath();      file=parentFile;      }    }

紫衣仙女

Environment.getExternalStorageState() 返回内部SD安装点的路径,例如“ / mnt / sdcard”不,Environment.getExternalStorageDirectory()是指设备制造商认为是“外部存储”的任何内容。在某些设备上,这是可移动媒体,例如SD卡。在某些设备上,这是设备上闪存的一部分。此处,“外部存储空间”是指“至少在Android 1.x和2.x上可以通过安装在主机上的USB大容量存储模式访问的内容”。但是问题是关于外部SD。如何获得“ / mnt / sdcard / external_sd”之类的路径(可能因设备而异)?如上所述,除了外部存储,Android没有“外部SD”的概念。如果设备制造商选择外部存储为板载闪存,并且还具有SD卡,则需要与该制造商联系,以确定是否可以使用SD卡(不保证)以及适用的规则。使用它,例如使用什么路径。试试看:Manifest.xml:<receiver android:name=".MyReceiver">&nbsp; &nbsp; <intent-filter>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<action android:name="android.intent.action.ums_connected" />&nbsp; &nbsp; &nbsp;</intent-filter>&nbsp; </receiver>我的接收器:public class MyReceiver extends BroadcastReceiver{if (intent.getAction().equalsIgnoreCase(&nbsp; &nbsp; &nbsp; &nbsp; "android.intent.action.UMS_CONNECTED")) {...}}
打开App,查看更多内容
随时随地看视频慕课网APP