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>