PhoneGap ----- Device Infomation, Network State and four kinds

Source: Internet
Author: User

The first, we can lead how to get the device Infomation! It's very convenient by Phonegap! At least, I think so!


[Html]
<! DOCTYPE html>
<Html>
<Head>
<Title> My Device </title>
<Script type = "text/javascript" charset = "UTF-8" src = "cordova. js"> </script>
<Script type = "text/javascript" charset = "UTF-8">
 
Function onLoad ()
{
Document. addEventListener ("deviceready", onDeviceReady, false );
}

Function onDeviceReady ()
{
Var myDiv = document. getElementById ('props ');
MyDiv. innerHTML = 'device Name: '+ Device. name +' <br/> '+
'Device PhoneGap: '+ Device. phonegap +' <br/> '+
'Device Platform: '+ Device. platform +' <br/> '+
'Device UUID: '+ Device. uuid +' <br/> '+
'Device Version: '+ Device. version +' <br/> ';
}

</Script>
</Head>
<Body onLoad = "onLoad ()">
<P id = "props"> Loading device properties... </p>
</Body>
</Html>

<! DOCTYPE html>
<Html>
<Head>
<Title> My Device </title>
<Script type = "text/javascript" charset = "UTF-8" src = "cordova. js"> </script>
<Script type = "text/javascript" charset = "UTF-8">

Function onLoad ()
{
Document. addEventListener ("deviceready", onDeviceReady, false );
}

Function onDeviceReady ()
{
Var myDiv = document. getElementById ('props ');
MyDiv. innerHTML = 'device Name: '+ Device. name +' <br/> '+
'Device PhoneGap: '+ Device. phonegap +' <br/> '+
'Device Platform: '+ Device. platform +' <br/> '+
'Device UUID: '+ Device. uuid +' <br/> '+
'Device Version: '+ Device. version +' <br/> ';
}

</Script>
</Head>
<Body onLoad = "onLoad ()">
<P id = "props"> Loading device properties... </p>
</Body>
</Html>
The second, we can check the network state:


[Html]
<! DOCTYPE html>
<Html>
<Head>
<Title> Connectivity Example </title>
<Script type = "text/javascript" charset = "UTF-8" src = "cordova. js"> </script>
<Script type = "text/javascript" charset = "UTF-8">
 
Document. addEventListener ("deviceready", onDeviceReady, false );

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>

<! DOCTYPE html>
<Html>
<Head>
<Title> Connectivity Example </title>
<Script type = "text/javascript" charset = "UTF-8" src = "cordova. js"> </script>
<Script type = "text/javascript" charset = "UTF-8">

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

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>

The third, the cases of four kinds of communications:


[Html]
<! DOCTYPE html>
<Html>
<Head>
<Title> PhoneGap Event Example </title>
 
<Script type = "text/javascript" charset = "UTF-8" src = "cordova. js"> </script>
<Script type = "text/javascript" charset = "UTF-8">
 
Function onLoad ()
{
Document. addEventListener ("deviceready", onDeviceReady, false );
}

Function onDeviceReady (){
}

Function showAlert (){
Navigator. notification. alert (
'Game Over! ', // Message
AlertCallback, // callback
'Game over ',
'Done' // buttonName
);
}

Function alertCallback (){
}

Function onConfirm (button ){
Alert (You selected button + button );
}

Function showConfirm (){
Navigator. notification. confirm (
'Game Over! ',
OnConfirm,
'Game over ',
'Restart, Exit'
);
}

Function playBeep (){
Navigator. notification. beep (2 );
}

Function vibrate (){
Navigator. notification. vibrate (4000 );
}

</Script>
</Head>
<Body onLoad = "onLoad ()">
<P> <a href = "#" onClick = "showAlert (); return false;"> Show Alert </a> </p>
<P> <a href = "#" onClick = "showConfirm (); return false;"> Show Confirmation </a> </p>
<P> <a href = "#" onClick = "playBeep (); return false;"> Play Beep </a> </p>
<P> <a href = "#" onClick = "vibrate (); return false;"> Vibrate </a> </p>
</Body>
</Html>

Related Article

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.