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
Contributor
Posts: 12
Registered: ‎10-29-2011
My Device: 9300 Curve 3G
My Carrier: Vodafone

Not able to connect to internet J2ME application on Blackberry.

Dear All, Following is my piece of code, which is working flawlessly on Nokia phones with GPRS connectivity, when I test it on Blackberry it first gave me an error about APN Settings not enabled when I enabled that it gave me a DNS error. Note I was testing it on the actual blackberry device. Strangely I do have internet enabled on my Blackberry 9300 phone and I am able to access all websites on my browser, I am using Vodafone blackberry internet service in India. Kindly someone please tell me what do I need to do get my code working, /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package internet; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; /** * * @author ameya */ public class InternetConnector { public static String getDataFromGPRS(String url, final String data[]) { if (data != null && data.length > 0) { StringBuffer appendParams = new StringBuffer(""); for (int i = 0; i < data.length - 1; i += 2) { appendParams.append(data[i]); appendParams.append("="); appendParams.append(data[i + 1]); appendParams.append("&"); } String finalURLParams = appendParams.toString().substring(0, appendParams.length() - 1); url = url + "?" + finalURLParams; } System.out.println("The URL is: " + url); try { return getDataFromURL(url); } catch (Exception e) { return "ERROR: " + e.getMessage(); } } private static String getDataFromURL(String url) throws IOException, Exception { HttpConnection connection = null; InputStream is = null; OutputStream os = null; StringBuffer stringBuffer = new StringBuffer(); try { connection = (HttpConnection) Connector.open(url); connection.setRequestMethod(HttpConnection.GET); connection.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT"); connection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Confirguration/CLDC-1.0"); connection.setRequestProperty("Content-Language", "en-CA"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); os = connection.openOutputStream(); is = connection.openDataInputStream(); int ch; while ((ch = is.read()) != -1) { stringBuffer.append((char) ch); } System.out.println(stringBuffer.toString()); return stringBuffer.toString().trim(); } catch (Exception ex) { throw ex; } finally { if (is != null) { is.close(); } if (os != null) { os.close(); } if (connection != null) { connection.close(); } } } }
Contributor
Posts: 12
Registered: ‎10-29-2011
My Device: 9300 Curve 3G
My Carrier: Vodafone

Re: Not able to connect to internet J2ME application on Blackberry.

I am sorry for the above post, but I am unable to post my code, not getting the pop up, But I am using simple J2ME, and following are main lines of my code, connection = (HttpConnection) Connector.open(url); connection.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT"); connection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Confirguration/CLDC-1.0"); connection.setRequestProperty("Content-Language", "en-CA"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); os = connection.openOutputStream(); is = connection.openDataInputStream();
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Not able to connect to internet J2ME application on Blackberry.

Connecting to the network on BB is not as simple as we would all like it to be.

 

There are loads of places that document various aspects of this.  I recommend that two network transports videos you will find if you search for network.  You might find the KB articles referenced in this Thread useful too.

http://supportforums.blackberry.com/t5/Java-Development/HTTPConnection-suffix-problem/td-p/1396919

 

Look up the documentation for ConnectionFactory if you are running OS 5.0 or later too.

 

And you might find the two network related sticky Threads I started useful - see the links that are stuck at the top of the list of Threads.

 

Hopefully one of these will shed some light on our issue.

 

Come back for help if these are not appropriate or you have further questions. 

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Not able to connect to internet J2ME application on Blackberry.

@AMZDeCoder: Just on your "posting code" issue, when you clikc reply there is a icon that looks like a clipboard with a C on it (next to the one with the MS Word logo). Use that to post your code.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Contributor
Posts: 12
Registered: ‎10-29-2011
My Device: 9300 Curve 3G
My Carrier: Vodafone

Re: Not able to connect to internet J2ME application on Blackberry.

Hi Peter_Strange,

 

The thing is I want same application that works in Nokia to work in blackberry, is that not possible ??? Then I will give up on blackberry totally and remove it from my list of supported phones.

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

Re: Not able to connect to internet J2ME application on Blackberry.

On some BlackBerry phones, you can just specify the URL and the branding on the phone for a BIS device, or the fact that it is BES connected on a BES device will route the connection appropriately.  However in my experience, this does not work on all phones.  In addition, you might then be using a connection that costs the user, depending on their data plan.

 

The way round this is to add a connection suffix, which specifies the actual network gateway your connection will be routed through.  The first KB article that you were linked to describes the available connection suffixes.

 

But the short answer to your question is that the same application may not work on BlackBerry devices, or more specifically, your application may not be able to connect. 

 

I guess this means goodbye......  Smiley Sad

Highlighted
Contributor
Posts: 12
Registered: ‎10-29-2011
My Device: 9300 Curve 3G
My Carrier: Vodafone

Re: Not able to connect to internet J2ME application on Blackberry.

Well it seems then my application WILL not work on BLACKBERRY... Good bye blackberry for me Smiley Happy.