Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import javax.microedition.io.Connection;
- import javax.microedition.io.Connector;
- import net.rim.device.api.system.*;
- public class ConnectionManager implements GlobalEventListener, CoverageStatusListener {
- private static ConnectionManager _manager;
- private boolean _isSimulator;
- private boolean _mdsSupport;
- private boolean _bisSupport;
- private boolean _wapSupport;
- private boolean _wifiSupport;
- private ConnectionManager(){
- setCoverage();
- }
- public static ConnectionManager getInstance(){
- if (_manager == null) _manager = new ConnectionManager();
- return _manager;
- }
- private boolean isWifi() {
- boolean wifi;
- if (WLANInfo.getWLANState() == 4620) wifi = true;
- else wifi = false;
- return wifi;
- }
- public Connection getConnection(String name, int mode, boolean timeouts) throws IOException {
- if(DeviceInfo.isSimulator()) name = name.concat(";deviceside=true;ConnectionTimeout=20000");
- else if(isWifi()) name = name.concat(";deviceside=true;interface=wifi");
- else if(_mdsSupport) name = name.concat(";deviceside=false");
- else if(_bisSupport) name = name.concat(";deviceside=false;ConnectionType=mds-public;EndToEndRequired;ConnectionTimeout=45000");
- else if(!_wapSupport) name = name.concat(";deviceside=true");
- return Connector.open(name, mode, timeouts);
- }
- public String getConnectionType() {
- if (_mdsSupport) return "MDS";
- if (_bisSupport) return "BIS-B";
- if (_wapSupport) return "WAP";
- else return "Direct TCP";
- }
- private void setCoverage(){
- if(CoverageInfo.isCoverageSufficient(2)) _mdsSupport = true;
- if(CoverageInfo.isCoverageSufficient(4)) _bisSupport = true;
- }
- public void coverageStatusChanged(int newCoverage) {
- if((newCoverage & 2) == 2) _mdsSupport = true;
- if((newCoverage & 4) == 4) _bisSupport = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement