Use offlineLogin to test the wireless connection before a login attempt is made. If the wireless connection option has been switched off, the loginToSync call takes a long time to fail when a wrong password is entered, with an 'Invalid Password' error message appearing only after a timeout.
import net.rim.device.api.system.RadioInfo; …… public class Test { public static void main(String[] args) { if (isWirelessConnected ()) { XXDB.loginToSync(username, password); } else { boolean result = XXDB. offlineLogin(username, password); if (result == false) { throw new Exception("Offline login failed"); } } } public static boolean isWirelessConnected() { boolean isWirelessConnected = true; int state = RadioInfo.getState(); int signal = RadioInfo.getSignalLevel(); if (state == RadioInfo.STATE_OFF || state == RadioInfo.STATE_LOWBATT || signal == RadioInfo.LEVEL_NO_COVERAGE) { isWirelessConnected = false; } return isWirelessConnected; } }
If your application uses BES or BIS connectivity to connect to an Unwired Server from a BlackBerry device, the application can automatically switch to use Wi-Fi when it becomes available. If using a direct TCP connection, the application must explicitly specify a Wi-Fi transport type.
DatabaseClass.getSynchronizationProfile().setString("transport", "WIFI")