Android TV和Android 一样的,想要监听usb的挂载,可以监听以下的广播
监听USB插入以及移除
注意这个是usb的插入和移除,不只是U盘哦
UsbManager.ACTION_USB_DEVICE_ATTACHED
UsbManager.ACTION_USB_DEVICE_DETACHED
监听usb u盘的的挂载
- 静态注册
<receiver android:name=".receiver.USBReceiver">
<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_REMOVED"/>
<data android:scheme="file"/>
</intent-filter>
</receiver>
- 动态注册
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED);//插入
intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);//拔出
intentFilter.addAction(Intent.ACTION_MEDIA_REMOVED); //完全拔出
intentFilter.addDataScheme("file");//没有这行监听不起作用
registerReceiver(receiver, intentFilter);