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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


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".

Highlighted
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...

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...