Posted by: iBNuX | May 2, 2010

Auto Check Connection for Blackberry

script ini akan menentukan jalur secara otomatis dalam melakukan koneksi http/tcp.
apakah melalui Wifi, MDS/BES dan directTCP.

simpan dengan nama ConnString.java

import net.rim.device.api.system.CoverageInfo;
import net.rim.device.api.system.DeviceInfo;
import net.rim.device.api.system.WLANInfo;

public final class ConnString {
    public static String getConnectionString()
    {
        String st = "";
        try{
	    //The Device is a simultaor --> TCP
	        if (DeviceInfo.isSimulator()){
	            return "";
        	}else if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
	            st =  ";interface=wifi";
	        } else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS){
	            st = ";deviceside=false";// use the clients blackberry enterprise server
	        }else{
	            st = ";deviceside=true";// let the phone do the work if it can
	        }
        }catch(Exception e){
            System.out.println(e.toString());
        }
	            return st + ";ConnectionTimeout=45000";
    }

}

gunakan tiap akan melakukan koneksi pada url
contoh:

HttpConnection connection = null;
connection = (HttpConnection) Connector.open("http://ibnux.netapa?ini=itu"+
ConnString.getConnectionString(), Connector.READ, true);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: