欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android判斷phonegap是否聯(lián)網(wǎng)且加載super.loadUrl網(wǎng)址

 更新時(shí)間:2013年02月26日 15:29:48   作者:  
android判斷phonegap是否聯(lián)網(wǎng)動(dòng)態(tài)加載super.loadUrl網(wǎng)址,接下來(lái)本文所提供的知識(shí)會(huì)幫助你解決以上問(wèn)題,感興趣的你可不要錯(cuò)過(guò)了哈
復(fù)制代碼 代碼如下:

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);
}
}

解釋下 第四行 顯示啟動(dòng)畫(huà)面
第七行判斷是否聯(lián)網(wǎng) 如果聯(lián)網(wǎng)加載遠(yuǎn)程地址 如果不聯(lián)網(wǎng)加載本地地址
別忘網(wǎng)絡(luò)權(quán)限
error.html錯(cuò)誤界面代碼
主要js代碼
復(fù)制代碼 代碼如下:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
checkConnection();
document.addEventListener("backbutton", eventBackButton, false); //返回鍵
//document.addEventListener("menubutton", eventMenuButton, false); //menu
}
function checkConnection() {
var networkState = navigator.network.connection.type;
if( networkState == Connection.NONE ) {
navigator.notification.confirm('請(qǐng)確認(rèn)網(wǎng)絡(luò)連接已經(jīng)開(kāi)啟', showAlert , '提示', '確定');
return false;
}
}
function showAlert(button) {
if( button==1 ) {
navigator.app.exitApp();
}
return false;
}
function eventBackButton(){
navigator.notification.confirm('確認(rèn)退出?', showConfirm, '退出軟件', '確定,取消');
}
function showConfirm(button) {
if( button==1 ) {
document.removeEventListener("backbutton", eventBackButton, false); //注銷(xiāo)返回鍵
navigator.app.exitApp();
}
}

曾經(jīng)有人很奇怪為什么要用java判斷是否聯(lián)網(wǎng)而不直接在js里面判斷主要原因:
1,不愿意讓他顯示www.xxxxx.com網(wǎng)址不能訪問(wèn)情況
2,避免直接訪問(wèn)實(shí)際網(wǎng)址
3,而且免去本地判斷跳轉(zhuǎn)遠(yuǎn)程地址中間空白頁(yè)面

相關(guān)文章

最新評(píng)論