android 监听USB连接状态

    xiaoxiao2021-03-25  86

    public class UPanBroadcastReceiver extends BroadcastReceiver { private boolean UpanMounted = false; @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub if (intent.getAction().equals("android.hardware.usb.action.USB_STATE")) { boolean connected = intent.getExtras().getBoolean("connected"); if (connected) { Toast.makeText(context, "USB 插上", 1000).show(); }else { Toast.makeText(context, "USB 拔掉", 1000).show(); } } } } xml静态注册 <receiver android:name="com.wdh.system.UPanBroadcastReceiver"> <intent-filter> <action android:name="android.hardware.usb.action.USB_STATE"/> </intent-filter> </receiver>

    转载请注明原文地址: https://ju.6miu.com/read-21657.html

    最新回复(0)