PhoneGap API help documentation-Connection)

Source: Internet
Author: User

The Connection object provides access to the cellular and wi-fi Connection information of the device.
Access this object through the navigator. network interface.

Attribute:
Connection. type


Constant:
Connection. UNKNOWN
Connection. ETHERNET
Connection. WIFI
Connection. CELL_2G
Connection. CELL_3G
Connection. CELL_4G
Connection. NONE


Connection. type

 

Check the active network connection in use.

Note:
This attribute is a quick method for determining the network connection status and connection type of a device.

Supported platforms:
IOS
Android
BlackBerry WebWorks (OS 5.0 or later)


Simple Example:
<Span style = "font-size: 13px;"> function checkConnection (){

Var networkState = navigator. network. connection. type;

Var states = {};

States [Connection. UNKNOWN] = 'unknown connection ';

States [Connection. ETHERNET] = 'ethernet connection ';

States [Connection. WIFI] = 'wifi connection ';

States [Connection. CELL_2G] = 'cell 2G connection ';

States [Connection. CELL_3G] = 'cell 3G connection ';

States [Connection. CELL_4G] = 'cell 4G connection ';

States [Connection. NONE] = 'no network connection ';

Alert ('Connection type: '+ states [networkState]);

}

CheckConnection (); </span>
Copy the complete sample code:
<! DOCTYPE html>

<Html>

<Head>

<Title> navigator. network. connection. type Example </title>

<Script type = "text/javascript" charset = "UTF-8" src = "phonegap. js"> </script>

<Script type = "text/javascript" charset = "UTF-8">

// Wait for loading PhoneGap

Document. addEventListener ("deviceready", onDeviceReady, false );

// After the PhoneGap is loaded, you can call the PhoneGap method safely.

Function onDeviceReady (){

CheckConnection ();

}

Function checkConnection (){

Var networkState = navigator. network. connection. type;

Var states = {};

States [Connection. UNKNOWN] = 'unknown connection ';

States [Connection. ETHERNET] = 'ethernet connection ';

States [Connection. WIFI] = 'wifi connection ';

States [Connection. CELL_2G] = 'cell 2G connection ';

States [Connection. CELL_3G] = 'cell 3G connection ';

States [Connection. CELL_4G] = 'cell 4G connection ';

States [Connection. NONE] = 'no network connection ';

Alert ('Connection type: '+ states [networkState]);

}

</Script>

</Head>

<Body>

<P> A dialog box will report the network state. </p>

</Body>

</Html>

Author: LuoXianXion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.