isa*_*ent 5 android usb-drive android-sdcard removable-storage android-broadcastreceiver
我有一部 Android 6.0 手机,配有内部存储器、可移动 SD 卡和插入手机中的 USB OTG(带微型 USB 插孔的笔式驱动器)。Android设备中弹出可移动SD卡和USB OTG:“设置”->“存储和USB”。我可以在该设备中安装可移动SD卡和USB OTG。例如,我安装了可移动 SD,并希望将此事件与 USB OTG 的安装区分开来。我可以在接收器中执行的唯一操作
<receiver
android:name=".receiver.RemovableMediaReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<action android:name="android.intent.action.MEDIA_UNMOUNTED"/>
<action android:name="android.intent.action.MEDIA_EJECT"/>
<action android:name="android.intent.action.MEDIA_BAD_REMOVAL"/>
<data android:scheme="file"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
挂载时为android.intent.action.MEDIA_MOUNTED,挂载的 SD 卡的根目录路径作为此操作的额外内容 - /storage/A13D-EF43。USB OTG 安装事件也是如此。唯一的区别在于安装的 USB OTG 的名称 - 路径是/storage/BD76-24ED。
如果我在安装之前没有 API 调用来获取 SD 或 USB OTG 的名称,以便将其与android.intent.action.MEDIA_MOUNTED中的额外(路径)进行比较,我如何了解安装了哪种媒体 - SD 或 USB OTG ?
| 归档时间: |
|
| 查看次数: |
640 次 |
| 最近记录: |