<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
--><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
<meta name="generator" content="joDoc">
<title>Apache Cordova API Documentation</title>
<link rel="stylesheet" type="text/css" href="index.css">
<link rel="stylesheet" type="text/css" href="mobile.css" media="only screen and (max-device-width: 1024px)">
<link rel="stylesheet" type="text/css" href="prettify/prettify.css">
</head>
<body>
        <div id="header">
            <h1><a href="index.html">Apache <strong>Cordova</strong> Documentation</a></h1>
            <small>
                <select><optgroup label="English" value="en">
<option value="edge">edge</option>
<option value="2.9.0rc1">2.9.0rc1</option>
<option value="2.9.0">2.9.0</option>
<option value="2.8.0">2.8.0</option>
<option value="2.7.0rc1">2.7.0rc1</option>
<option value="2.7.0">2.7.0</option>
<option value="2.6.0rc1">2.6.0rc1</option>
<option value="2.6.0">2.6.0</option>
<option value="2.5.0rc1">2.5.0rc1</option>
<option value="2.5.0">2.5.0</option>
<option value="2.4.0rc1">2.4.0rc1</option>
<option value="2.4.0">2.4.0</option>
<option value="2.3.0rc2">2.3.0rc2</option>
<option value="2.3.0rc1">2.3.0rc1</option>
<option value="2.3.0">2.3.0</option>
<option value="2.2.0rc2">2.2.0rc2</option>
<option value="2.2.0rc1">2.2.0rc1</option>
<option value="2.2.0">2.2.0</option>
<option value="2.1.0rc2">2.1.0rc2</option>
<option value="2.1.0rc1">2.1.0rc1</option>
<option value="2.1.0">2.1.0</option>
<option value="2.0.0rc1">2.0.0rc1</option>
<option value="2.0.0">2.0.0</option>
<option value="1.9.0rc1">1.9.0rc1</option>
<option value="1.9.0">1.9.0</option>
<option value="1.8.1">1.8.1</option>
<option value="1.8.0rc1">1.8.0rc1</option>
<option value="1.8.0">1.8.0</option>
<option value="1.7.0rc1">1.7.0rc1</option>
<option selected value="1.7.0">1.7.0</option>
<option value="1.6.1">1.6.1</option>
<option value="1.6.0rc1">1.6.0rc1</option>
<option value="1.6.0">1.6.0</option>
<option value="1.5.0rc1">1.5.0rc1</option>
<option value="1.5.0">1.5.0</option>
</optgroup>
<optgroup label="Japanese" value="jp">
<option value="2.2.0">2.2.0</option>
<option value="2.1.0">2.1.0</option>
<option value="2.0.0">2.0.0</option>
<option value="1.9.0">1.9.0</option>
<option value="1.8.1">1.8.1</option>
<option value="1.7.0">1.7.0</option>
</optgroup>
<optgroup label="Korean" value="kr"><option value="2.0.0">2.0.0</option></optgroup></select></small>
        </div>
        <div id="subheader">
            <h1>Connection</h1>
            <small><select><option value="Connection">Connection</option>
<option value="Connection_properties">      - Properties</option>
<option value="Connection_constants">      - Constants</option>
<option value="Connection_wp7_quirk">      - WP7 Quirk</option>
<option value="Connection_ios_quirk">      - iOS Quirk</option>
<option value="Connection_bada_quirk">      - Bada Quirk</option>
<option value="connection.type">connection.type</option>
<option value="connection.type_description">      - Description</option>
<option value="connection.type_supported_platforms">      - Supported Platforms</option>
<option value="connection.type_quick_example">      - Quick Example</option>
<option value="connection.type_full_example">      - Full Example</option></select></small>
        </div>

        <div id="sidebar">
            <div class="vertical_divider"></div>
        <h1>API Reference</h1>
<ul>
<li><a href="cordova_accelerometer_accelerometer.md.html#Accelerometer">Accelerometer</a></li>
<li><a href="cordova_camera_camera.md.html#Camera">Camera</a></li>
<li><a href="cordova_media_capture_capture.md.html#Capture">Capture</a></li>
<li><a href="cordova_compass_compass.md.html#Compass">Compass</a></li>
<li><a href="cordova_connection_connection.md.html#Connection">Connection</a></li>
<li><a href="cordova_contacts_contacts.md.html#Contacts">Contacts</a></li>
<li><a href="cordova_device_device.md.html#Device">Device</a></li>
<li><a href="cordova_events_events.md.html#Events">Events</a></li>
<li><a href="cordova_file_file.md.html#File">File</a></li>
<li><a href="cordova_geolocation_geolocation.md.html#Geolocation">Geolocation</a></li>
<li><a href="cordova_media_media.md.html#Media">Media</a></li>
<li><a href="cordova_notification_notification.md.html#Notification">Notification</a></li>
<li><a href="cordova_storage_storage.md.html#Storage">Storage</a></li>
</ul>
<h1>Guides</h1>
<ul>
<li><a href="guide_getting-started_index.md.html#Getting%20Started%20Guides">Getting Started Guides</a></li>
<li><a href="_index.html">Keyword Index</a></li>
</ul>
</div>

        <div id="scrollable">
            <div id="content">
                <h1><a name="Connection">Connection</a></h1>

<blockquote>
  <p>The <code>connection</code> object gives access to the device's cellular and wifi connection information.</p>
</blockquote>

<p>This object is accessed under the <code>navigator.network</code> interface.</p>

<h2>
<a name="Connection_properties">Properties</a>
</h2>

<ul>
<li><a href="cordova_connection_connection.md.html#connection.type">connection.type</a></li>
</ul>
<h2>
<a name="Connection_constants">Constants</a>
</h2>

<ul>
<li>
<a href="cordova_connection_connection.md.html#Connection">Connection</a>.UNKNOWN</li>
<li>
<a href="cordova_connection_connection.md.html#Connection">Connection</a>.ETHERNET</li>
<li>
<a href="cordova_connection_connection.md.html#Connection">Connection</a>.WIFI</li>
<li>
<a href="cordova_connection_connection.md.html#Connection">Connection</a>.CELL_2G</li>
<li>
<a href="cordova_connection_connection.md.html#Connection">Connection</a>.CELL_3G</li>
<li>
<a href="cordova_connection_connection.md.html#Connection">Connection</a>.CELL_4G</li>
<li>
<a href="cordova_connection_connection.md.html#Connection">Connection</a>.NONE</li>
</ul>
<h2>
<a name="Connection_wp7_quirk">WP7 Quirk</a>
</h2>

<ul>
<li>
<strong>type:</strong>
Windows Phone Emulator always reports navigator.network.<a href="cordova_connection_connection.md.html#connection.type">connection.type</a> is <a href="cordova_connection_connection.md.html#Connection">Connection</a>.UNKNOWN</li>
</ul>
<h2>
<a name="Connection_ios_quirk">iOS Quirk</a>
</h2>

<ul>
<li>
<strong>type:</strong>
iOS can only report whether the device is on a cellular connection, not
of what type, thus it will always report as CELL_2G</li>
</ul>
<h2>
<a name="Connection_bada_quirk">Bada Quirk</a>
</h2>

<ul>
<li>Bada can only report if device is on Wifi or connected to cellular connection CELL_2G ( type not reported )</li>
</ul>
<hr>
<h1><a name="connection.type">connection.type</a></h1>

<p>Checks the active network connection that is being used.</p>

<h2>
<a name="connection.type_description">Description</a>
</h2>

<p>This property is a fast way to determine the device's network connection state, and type of connection.</p>

<h2>
<a name="connection.type_supported_platforms">Supported Platforms</a>
</h2>

<ul>
<li>iOS</li>
<li>Android</li>
<li>BlackBerry WebWorks (OS 5.0 and higher)</li>
<li>Windows Phone 7 ( Mango )</li>
<li>Bada 2.x</li>
</ul>
<h2>
<a name="connection.type_quick_example">Quick Example</a>
</h2>

<pre class="prettyprint"><code>function checkConnection() {
    var networkState = navigator.network.<a href="cordova_connection_connection.md.html#connection.type">connection.type</a>;

    var states = {};
    states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.UNKNOWN]  = 'Unknown connection';
    states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.ETHERNET] = 'Ethernet connection';
    states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.WIFI]     = 'WiFi connection';
    states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.CELL_2G]  = 'Cell 2G connection';
    states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.CELL_3G]  = 'Cell 3G connection';
    states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.CELL_4G]  = 'Cell 4G connection';
    states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.NONE]     = 'No network connection';

    alert('<a href="cordova_connection_connection.md.html#Connection">Connection</a> type: ' + states[networkState]);
}

checkConnection();
</code></pre>

<h2>
<a name="connection.type_full_example">Full Example</a>
</h2>

<pre class="prettyprint"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;navigator.network.<a href="cordova_connection_connection.md.html#connection.type">connection.type</a> Example&lt;/title&gt;

    &lt;script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" charset="utf-8"&gt;

    // Wait for Cordova to load
    // 
    document.addEventListener("<a href="cordova_events_events.md.html#deviceready">deviceready</a>", onDeviceReady, false);

    // Cordova is loaded and it is now safe to make calls Cordova methods
    //
    function onDeviceReady() {
        checkConnection();
    }

    function checkConnection() {
        var networkState = navigator.network.<a href="cordova_connection_connection.md.html#connection.type">connection.type</a>;

        var states = {};
        states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.UNKNOWN]  = 'Unknown connection';
        states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.ETHERNET] = 'Ethernet connection';
        states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.WIFI]     = 'WiFi connection';
        states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.CELL_2G]  = 'Cell 2G connection';
        states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.CELL_3G]  = 'Cell 3G connection';
        states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.CELL_4G]  = 'Cell 4G connection';
        states[<a href="cordova_connection_connection.md.html#Connection">Connection</a>.NONE]     = 'No network connection';

        alert('<a href="cordova_connection_connection.md.html#Connection">Connection</a> type: ' + states[networkState]);
    }

    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;A dialog box will report the network state.&lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

            </div>
        </div>

        <!-- Functionality and Syntax Highlighting -->
        <script type="text/javascript" src="index.js"></script><script type="text/javascript" src="prettify/prettify.js"></script>
</body>
</html>
