我在网上搜索了我的问题的解决方案,发现了许多相关的线程,不幸的是,提供的解决方案都不适用于我的案例。我是 android 开发的新手,并遵循了Apache Cordova上的文档!用于配置。
问题:未触发 deviceready 事件,以下是我的代码和配置以及错误日志。请指教我做错了什么,谢谢!!!
模拟器
AVD Device: nexus 7
Target: Android 4.2
Memory RAM: 512
MainActivity.java
package com.example.pollo;
import android.os.Bundle;
import org.apache.cordova.*;
import android.app.Activity;
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
索引.html
<html>
<head>
<title></title>
<script src="cordova-2.2.0.js"></script>
<script>
function onLoad(){
console.log("Now Loading");
document.addEventListener("deviceready", myDeviceReadyListener, false);
}
function myDeviceReadyListener(){
console.log("Device ready");
navigator.notification.alert("Phone is ready!");
var myDiv = document.getElementById('props');
myDiv.innerHTML = 'Device Name: ' + device.name;
}
</script>
</head>
<body onload="onLoad()">
<h1>X App V.11</h1>
<p id="props">Loading device properties...</p>
</body>
</html>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pollo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:name="com.example.pollo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
配置
assets>www>cordova-2.2.0.js
assets>www>index.html
res>xml>config.xml
AndroidManifest.xml
libs>cordova-2.2.0.jar
libs>android-support-v13.jar
Logcat - 错误日志
12-31 01:50:58.323: E/Trace(659): error opening trace file: No such file or directory (2)
12-31 01:51:45.653: E/StrictMode(552): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d1b278 that was originally bound here
调用了 onLoad() 但未调用 myDeviceReadyListener() 〜它与我选择的模拟器有什么关系吗?