Code example for NetworkInfo

Methods: getSubtypeName, getTypeName, isConnected

0
     */ 
    private String getConnectionInfo(NetworkInfo info) {
        String type = TYPE_NONE;
        if (info != null) {
            // If we are not connected to any network set type to none 
            if (!info.isConnected()) {
                type = TYPE_NONE;
            } 
            else { 
                type = getType(info);
            } 
        } 
        return type;
    } 
 
    /** 
     * Create a new plugin result and send it back to JavaScript 
     * 
     * @param connection the network info to set as navigator.connection 
     */ 
    private void sendUpdate(String type) {
        PluginResult result = new PluginResult(PluginResult.Status.OK, type);
        result.setKeepCallback(true);
        this.success(result, this.connectionCallbackId);
 
        // Send to all plugins 
        this.ctx.postMessage("networkconnection", type);
    } 
 
    /** 
     * Determine the type of connection 
     * 
     * @param info the network info so we can determine connection type. 
     * @return the type of mobile network we are on 
     */ 
    private String getType(NetworkInfo info) {
        if (info != null) {
            String type = info.getTypeName();
 
            if (type.toLowerCase().equals(WIFI)) {
                return TYPE_WIFI;
            } 
            else if (type.toLowerCase().equals(MOBILE)) {
                type = info.getSubtypeName();
                if (type.toLowerCase().equals(GSM) ||
                        type.toLowerCase().equals(GPRS) ||
                        type.toLowerCase().equals(EDGE)) {
                    return TYPE_2G;
                }