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);

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *