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
Contributor
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

According to what I've been seeing already ha way to detect what is connected. But HTTPDemo should not give in mobile phone?

I just tried to run the application on the mobile phone with wifi option and set the "deviceside = false" and yet the message that appears is "java.io.IOException" I do not understand why it does not work! : S

Contributor
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

The modify code is:

 

HttpConnection httpConn = (HttpConnection)Connector.open(getUrl()+";interface=wifi");

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Get string from url

You might remember this KB article that I referenced previously.

 

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-con...

 

Have another look through this and see what each of the connection strings actually means.

 

For WiFi you need

";interface=wifi"

 

Note that these must be typed exactly as you see them.  So "deviceside = false" won't work because it does not have a ";" to start and there are spaces in it.  You should use

";deviceside=false"

This is for BES/MDS connections, I doubt your phone is a BES phone. 

 

But I really recommend that you do not try this way.  Use ConnectionFactory. 

Contributor
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

I've been researching the FactoryConnection and tried to implement but not how to get the text of this connection!

 

My code is:

 

//preferred transport types
int[] preferredTransportTypes = {TransportInfo.TRANSPORT_TCP_WIFI, TransportInfo.TRANSPORT_MDS,
TransportInfo.TRANSPORT_WAP2, TransportInfo.TRANSPORT_BIS_B, TransportInfo.TRANSPORT_TCP_CELLULAR,
TransportInfo.TRANSPORT_WAP};

//set preference in connection factory
ConnectionFactory factory = new ConnectionFactory();
factory.setPreferredTransportTypes(preferredTransportTypes);
factory.setAttemptsLimit(3);


//create connection using connectionDescriptor
ConnectionDescriptor conDescriptor = factory.getConnection(url);
HttpConnection httpConnection=null;

if(conDescriptor !=null){
httpConnection = (HttpConnection) conDescriptor.getConnection();
transportType = conDescriptor.getTransportDescriptor().getTransportType();
}

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Get string from url

If you have looked at HttpDemo (sorry I think I called it htmlDemo), you will see these lines:

 

                    StreamConnection s = null;

                    s = (StreamConnection)Connector.open(getUrl());

                    HttpConnection httpConn = (HttpConnection)s;

 

Basically after this line in your code:

 

httpConnection = (HttpConnection) conDescriptor.getConnection();

 

you have an HTTP connection.  And so the processing continues like HttpDemo, i.e. get response code and then read the input stream.

 

BTW, I recommend IOUtilities.streamToBytes as a quick way to read the entire Stream in.

 

Hope this helps.   

 

 

Contributor
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

Have a working code that I can show to see if I can understand putting it to work right?

 

Have tou is all confused and I really need to put this to work ASAP!

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Get string from url

Contributor
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

I had already found this example and what brings me back is the number 302, which does not know what it means!

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Get string from url

Is this the response code you are getting? 

 

If so, use the search facility here or use your favorite Internet search engine and look for Http code 302.  Hopefully that will explain it.

 

With redirects you need to chase down the actual address yourself - Browsers do this for you but when getting the data yourself you need to do it. 

 

 

Contributor
Posts: 41
Registered: ‎11-15-2012
My Device: Curve 9320
My Carrier: Optimus

Re: Get string from url

But with this code should not show the text received?