Copy codeThe Code is as follows: public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
Super. setIntegerProperty ("splashscreen", R. drawable. splash );
ConnectivityManager cwjManager = (ConnectivityManager) getSystemService (Context. CONNECTIVITY_SERVICE );
NetworkInfo info = cwjManager. getActiveNetworkInfo ();
If (info! = Null & info. isAvailable ()){
Super. loadUrl ("http://www.xxx.com", 4500 );
}
Else
{
Super. loadUrl ("file: // android_asset/www/error.html", 4500 );
}
}
The fourth line shows the startup screen.
Row 7 determines whether the network is connected. If the network is loaded, the remote address is loaded. If the network is not connected, the local address is loaded.
Do not forget network Permissions
Error.html error interface code
Main js CodeCopy codeThe Code is as follows: document. addEventListener ("deviceready", onDeviceReady, false );
Function onDeviceReady (){
CheckConnection ();
Document. addEventListener ("backbutton", eventBackButton, false); // return key
// Document. addEventListener ("menubutton", eventMenuButton, false); // menu
}
Function checkConnection (){
Var networkState = navigator. network. connection. type;
If (networkState = Connection. NONE ){
Navigator. notification. confirm ('make sure the network connection is enabled ', showAlert, 'hs',' OK ');
Return false;
}
}
Function showAlert (button ){
If (button = 1 ){
Navigator. app. exitApp ();
}
Return false;
}
Function eventBackButton (){
Navigator. notification. confirm ('Are you sure you want to exit? ', ShowConfirm, 'Exit the software', 'OK, cancel ');
}
Function showConfirm (button ){
If (button = 1 ){
Document. removeEventListener ("backbutton", eventBackButton, false); // cancel the return key
Navigator. app. exitApp ();
}
}
Some people once wondered why they used java to determine whether to connect to the Internet rather than directly determining the main reason in js:
1. Do not want to show him that the www.xxxxx.com website cannot be accessed
2. Avoid direct access to the actual website
3. Skip local judgment and jump to the blank page in the middle of the remote address