I am new to blackberry-7. In my application when I plug my phone into the cable (by means of the USB cable) I want to find if my blackberry connected with USB is in charging mode or transfer mode. How is it possible?
The USB can be detected asynchronously using SystemListener2
and also synchronously using DeviceInfo.getBatteryStatus
.
For what you need the battery status won't work because it probably charges in both normal and transfer modes, and then there's the problem of detecting the cable when the battery is full. So I'd try registering a SystemListener2
instance and hopefully the callback usbConnectionStateChange
will be passed the flag SystemListener2.USB_STATE_CABLE_CONNECTED as argument. When it is transferring, I'd expect the flags USB_STATE_ENUMERATED and USB_STATE_MS_INTERFACE_ENUMERATED to be received in the callback as well, but I've never tested it on a real device.
And I don't know what would happen if the device is already connected when the listener is registered.
To register the listener, call
Application.getApplication().addSystemListener(mySysListener2);