USB Connection Notification

You can receive a notification if the user connected the phone via a USB cable.

+5
source share
3 answers

Ajay

I was not able to find anything specific only for "USB Connected", but there are several broadcast actions that may be of interest in this case, depending on what you are trying to do:

  • ACTION_MEDIA_SHARED: External media is disconnected because it is shared with USB mass storage.
  • ACTION_UMS_CONNECTED: The device has switched to USB Mass Storage mode. This is mainly used for the USB settings panel.
  • ACTION_UMS_DISCONNECTED: The device has exited USB Mass Storage mode. This is mainly used for the USB settings panel.

, Broadcast Action USB , - :

USB-, , USB- ...

, LINK, , "USB Connected".

: -\

+4

; Debug , USB . , .

public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    // UsbManager.ACTION_USB_STATE -> "android.hardware.usb.action.USB_STATE" actually
    if (action.equals(UsbManager.ACTION_USB_STATE)) {
        Bundle extras = intent.getExtras();
        // UsbManager.USB_CONNECTED -> "connected" actually
        usbConnected = extras.getBoolean(UsbManager.USB_CONNECTED);
        ...

framework/base/service/java/com/android/server/NotificationManagerService.java. , .

+3

: API Level 5 , , -. ACTION_MAIN . . UiModeManager. : "android.intent.category.CAR_DOCK" public static final String CATEGORY_CAR_MODE

: API 8 , . : "android.intent.category.CAR_MODE"

+1

All Articles