Home > Mobile >  How android to monitor the usb plug of the serial port
How android to monitor the usb plug of the serial port

Time:04-16

Recently doing an android App, use a serial port communication, other works, but in the real machine debugging, real machine via a serial port to receive the data lines to connect the external equipment, after a serial port line pull, insert will not be able to receive the data again, listening to the usb plug of the radio doesn't work, please, advice

CodePudding user response:

Have you registered the usb radio

CodePudding user response:

refer to the second floor usecf response:
did you registered usb radio

Thank you teach, is that all right now, is to get the wrong broadcast messages

CodePudding user response:

Hello, I now also encountered the same problem, consult how to listen

CodePudding user response:

Mainly two events: 1, insert the USB; 2, USB authorization,

 
//apply for USB access
Private static final String ACTION_USB_PERMISSION="custom, literally. USB_PERMISSION";

/* *
* USB authorization
*/
Private final BroadcastReceiver usbPermissionReceiver=new BroadcastReceiver () {
@ Override
Public void onReceive (Context Context, Intent Intent) {
The String action=intent. GetAction ();
If (ACTION_USB_PERMISSION equals (action)) {//authorization: you also need to judge agrees to it or refuse, whether in view of the current equipment

} else if (UsbManager. ACTION_USB_DEVICE_ATTACHED. Equals (action)) {
The d (tag, "USB device inserted");

}
}
};


//registered in the right place to do
IntentFilter filter=new IntentFilter ();
Filter. AddAction (ACTION_USB_PERMISSION);
Filter. AddAction (UsbManager. ACTION_USB_DEVICE_ATTACHED);
Filter. AddAction (UsbManager. ACTION_USB_DEVICE_DETACHED);
The context. RegisterReceiver (usbPermissionReceiver, filter);

CodePudding user response:

Useful! Thank you very much,
  • Related