Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 31
Registered: ‎11-28-2008
My Device: Not Specified
Accepted Solution

Trying to detect when the USB cable is plugged in

I have been using the USBPortListener to try and get an indication as to when the USB cable has been plugged into the phone, and also when it gets diconnected. The problem is that only one function ever gets fired, and that is "getChannel", whenever I transmit data over the connection.

 

Obviously I must have a misunderstanding on how to use this listener, but I woud assume "connected" fires every time the cable is plugged in, same with "disconnected".

Developer
Posts: 484
Registered: ‎07-17-2008
My Device: Not Specified

Re: Trying to detect when the USB cable is plugged in

I think you want to use a system listener for this

Developer
Posts: 31
Registered: ‎11-28-2008
My Device: Not Specified

Re: Trying to detect when the USB cable is plugged in

Thank you, jonberry! That was just what I needed.

 

After implementing that, I got to thinking about the port listener again. Is there a nicer way to be able to tell when data has come in over the cable instead of reading the input stream over and over? I tried to use the USBPortListener's dataSent, dataReceived, and patternReceived and neither of these do anything...

Highlighted
Developer
Posts: 484
Registered: ‎07-17-2008
My Device: Not Specified

Re: Trying to detect when the USB cable is plugged in

Take a look at the USB sample in the demos.

 

I haven't tried this in a long while but I think the dataReceived method should work.

 

Make sure you've added a listener to your app.  Smiley Happy

Developer
Posts: 31
Registered: ‎11-28-2008
My Device: Not Specified

Re: Trying to detect when the USB cable is plugged in

Again, thank you. You pointed me in the right direction. I see the problem now; you have to register the channel first before you can get the callbacks.

 

I wish the documentation would tell you this little detail first...