can we receive notification if user connected there phone through USB cable.
Depending on your Android version, you must do either of the following: Drag down the status bar, tap Connected as <connection type> under Notifications, and select Camera (PTP). Go to Settings > Storage > Menu > USB computer connection, and select Camera (PTP).
So conclusion: this "USB Connector Connected" and "Disconnected" message loop might not be caused by moisture, but rather a somehow damaged USB C cable. Further, the message will go away if you wait long enough for the phone to work through the message buffer.
The reason it's saying connected-disconnected is because it's recognising that power is going to the phone, but not enough that it can actually charge it.
On some devices, it might be accessible from Settings > System > Advanced. Either way, once on the Developer Options page, scroll down a bit and tap on 'Default USB Configuration.
Actually there is one broadcast event; if you turned on Debug in your application settings, your will see a bug on your notification bar when you plugged usb. Following is the sample how it works;
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);
...
You can find this at framework/base/service/java/com/android/server/NotificationManagerService.java. Hope this helps.
Ajay,
I wasn't able to find anything specific to just "USB Connected," but there are a few Broadcast Actions that may be of interest in this case depending on what you are trying to accomplish:
ACTION_MEDIA_SHARED
: External media is unmounted because it is being shared via USB mass storage.ACTION_UMS_CONNECTED
: The device has entered USB Mass Storage mode. This is used mainly for the USB Settings panel.ACTION_UMS_DISCONNECTED
: The device has exited USB Mass Storage mode. This is used mainly for the USB Settings panel.There doesn't seem to be a Broadcast Action specific to USB simply being plugged in, you could also try doing something with:
ACTION_POWER_CONNECTED
: External power has been connected to the device.But this would go off for both USB connected to a computer and USB connect ONLY to a power source...
Interestingly, I also found this LINK simply stating that there was no Broadcast Action for "USB Connected".
You may be out of luck in this case :-\
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With