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
nathanpc
Posts: 134
Registered: ‎05-19-2012
My Device: Torch 9800, PlayBook 64GB, Dev Alpha
My Carrier: VIVO Brazil

Best Class to Get The Correct URL Suffix

I have a class that I wrote to get the URL Suffix, but I still have problems like when I'm only on WiFi and without a SIM card I get a "Tunnel failed" error and some of my users are reporting "APN Error" too. This is the class that I currently use:

package com.nathanpc.connection;

import rimx.network.TransportDetective;
import rimx.network.URLFactory;
import net.rim.device.api.servicebook.ServiceRecord;
import net.rim.device.api.system.CoverageInfo;
import net.rim.device.api.system.WLANInfo;

public class ConnectionCheck {
	public static boolean isConnected() {
		if (CoverageInfo.isOutOfCoverage()) {
			return false;
		} else {
			return true;
		}
	}
	
	public static String getConnectionURL(String url) {
		TransportDetective td = new TransportDetective();
		URLFactory urlFactory = new URLFactory(url);
		String final_url = url;
		
		if (td.isCoverageAvailable(TransportDetective.TRANSPORT_TCP_WIFI)) {
			final_url = urlFactory.getHttpTcpWiFiUrl();
		} else if (td.isCoverageAvailable(TransportDetective.TRANSPORT_BIS_B)) {
			final_url = urlFactory.getHttpBisUrl();
		} else if (td.isCoverageAvailable(TransportDetective.TRANSPORT_MDS)) {
			final_url = urlFactory.getHttpMdsUrl(false);
		} else if (td.isCoverageAvailable(TransportDetective.DEFAULT_TCP_CELLULAR)) {
			final_url = urlFactory.getHttpDefaultTcpCellularUrl(new ServiceRecord());
		}
		
		return final_url;
	}
}

Is there a really good one or just something wrong with my one? I only want something simple like that, just place the correct suffix at the end of the String and return it. I don't want something that I'll have to change my entire way to do HTTP requests.

If I helped you please click the "Like" button to support my work.
My apps: CherryNotes - Bookmarked - Requests
Social Me: about.me - Twitter
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Best Class to Get The Correct URL Suffix

In my opinion, the best class is ConnectionFactory.

Please use plain text.
Developer
nathanpc
Posts: 134
Registered: ‎05-19-2012
My Device: Torch 9800, PlayBook 64GB, Dev Alpha
My Carrier: VIVO Brazil

Re: Best Class to Get The Correct URL Suffix

Do you have any examples or how I can integrate with my current solution?

If I helped you please click the "Like" button to support my work.
My apps: CherryNotes - Bookmarked - Requests
Social Me: about.me - Twitter
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Best Class to Get The Correct URL Suffix

It doesn't integrate directly here.  Instead you replace the code that

a) invokes the getConnectionURL and then

b) subsequently opens a connection

with an invocation of ConnectionFactory. 

 

If you wanted to stick with what you currently have, I have the following recommendations:

 

a) Use MDS first

b) Use BIS-B second (assuming you are allowed to use BIS-B

Why use these first - becuase they will automatically use WiFi if it is working properly, so you get WiFi for free. 

c) Use WiFi

d) Use WAP2

e) Use TCP Dellular

 

Remember what you used, and if it worked, use it again.  Record the method you used to make sure you know what it is (or was) for debugging. 

Please use plain text.