3

Is it possible to identify if any USB cable is connected to the charging port of android phone with another end of cable as loosely connected?

I'm able to find when device is connected or disconnected from AC/USB power or if any media is mounted or unmounted but in all those cases, there is always a signal from another end which tells android about what type of connection it is.

But what if another end is not giving any signal? What if its a broken cable and hence don't have anything on the other end but yet connected into android charging port? Is it possible to find out such cases by some hardware level monitoring or something?

sourav.bh
  • 467
  • 1
  • 7
  • 20
Prakash
  • 449
  • 2
  • 4
  • 15
  • IIRC there's no way to determine if a cable is plugged in to a USB port without something on the other end providing a signal of some sort. I.e., there's no mechanical mechanism in USB ports to determine if there's something in them. – Dave Newton Jan 15 '19 at 17:15

2 Answers2

2

I should think not. I'm assuming you are using usb micro-b, and if there's just a cord dangling from your phone socket none of the five pins are connected to anything at the other and the fuse connecting the data cables d+ and d- is not live. Thus, your phone has no way of knowing if anything is connected. the VDD (+5V) is also dead and you wont even get recognition that the device is charging (because its not). OTG is also dead, so no recognition there either. Good Luck.

sh7411usa
  • 196
  • 1
  • 13
1

As far as I can see there is no broadcast for such a case. However you could query the UsbManager#getDeviceList and check the List. If it's empty then obviously there is nothing attached.

But there is no broadcast event for a non connected device.

Murat Karagöz
  • 35,401
  • 16
  • 78
  • 107