我正在使用Phonegap和jQuery mobile开发混合移动应用程序。我的应用程序工作正常,没有添加cordova.js,但当我添加cordova.js时,应用程序显示一些错误和崩溃。
我想在我的代码中添加Phonegap后退按钮事件,但它也无法正常工作,我希望cordova.js问题可能成为问题。我正在使用Cordova 2.4.0。
这是我的logcat和我的代码:
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/jquery.mobile-1.4.2.min.css">
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery.mobile-1.4.2.min.js"></script>
<script type="text/javascript" src="js/cordova.js"></script>
<script type="text/javascript">
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
document.addEventListener("backbutton", backKeyDown, true);
alert("Phonegap ready!");
console.log("PhoneGap is ready");
}
function backKeyDown() {
alert("bak event here ready!");
navigator.app.exitApp(); // To exit the app!
}
</script>
</head>
<body onload="onLoad()">
<div data-role="page">
<!-- header -->
<div data-role="header" style="background-color: #3399FF"class="ui-header-fixed" data-theme="b"><h1><font color="#ffffff">Mobile Bank</font></h1></div>
<div data-role="main" style="background-color: #DCDCDC">
<div align="center">
<img src="img/display_image2.jpg" style="width:330px;height:350px">
</div>
<ul data-role="listview" data-divider-theme="b" data-inset="true" >
<li>
<fieldset class="ui-field-contain" data-inline="true" data-inset="true">
<input type="password" data-inline="true" data-mini="true" placeholder="Mpin here" data-theme="b" id="mpin" >
<a href="" data-role="button" data-mini="false" rel="external" data-theme="a" id="log_btn" onclick="return Validate()">Login</a>
</fieldset>
<div align="right">
<a href="forget_pin_page.html" data-role="button" data-mini="true" data-inline="true" rel="external" data-theme="b" >Forgot Mpin?</a>
</div>
</li>
</ul>
<div data-role="ui-field-contain" align="center">
<table><tr><td width="50%" align="center">
<div data-role="popup" id="logout">
<div data-role="main">
<h2 align="center">Exit Application</h2>
<p> Are you sure want to Exit? </p>
<div align="center">
<a href="#" data-role="button" data-theme="b" rel="external"
data-inline="true">Yes</a> <a href="#" data-role="button"
data-theme="b" data-rel="back" data-inline="true">No</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
logcat的
05-23 01:16:30.510: E/AndroidRuntime(1272): FATAL EXCEPTION: main
05-23 01:16:30.510: E/AndroidRuntime(1272): Process: com.nest.mobilebanking, PID: 1272
05-23 01:16:30.510: E/AndroidRuntime(1272): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x4000010 (has extras) } in org.apache.cordova.NetworkManager$1@b3d99538
05-23 01:16:30.510: E/AndroidRuntime(1272): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:778)
05-23 01:16:30.510: E/AndroidRuntime(1272): at android.os.Handler.handleCallback(Handler.java:733)
05-23 01:16:30.510: E/AndroidRuntime(1272): at android.os.Handler.dispatchMessage(Handler.java:95)
05-23 01:16:30.510: E/AndroidRuntime(1272): at android.os.Looper.loop(Looper.java:136)
05-23 01:16:30.510: E/AndroidRuntime(1272): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-23 01:16:30.510: E/AndroidRuntime(1272): at java.lang.reflect.Method.invokeNative(Native Method)
05-23 01:16:30.510: E/AndroidRuntime(1272): at java.lang.reflect.Method.invoke(Method.java:515)
05-23 01:16:30.510: E/AndroidRuntime(1272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-23 01:16:30.510: E/AndroidRuntime(1272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-23 01:16:30.510: E/AndroidRuntime(1272): at dalvik.system.NativeStart.main(Native Method)
05-23 01:16:30.510: E/AndroidRuntime(1272): Caused by: java.lang.SecurityException: ConnectivityService: Neither user 10052 nor current process has android.permission.ACCESS_NETWORK_STATE.
05-23 01:16:30.510: E/AndroidRuntime(1272): at android.os.Parcel.readException(Parcel.java:1465)
05-23 01:16:30.510: E/AndroidRuntime(1272): at android.os.Parcel.readException(Parcel.java:1419)
答案 0 :(得分:2)
你的AndroidManifest文件中有'android.permission.ACCESS_NETWORK_STATE'吗? Logcat说你没有它,所以加上它。