我是科尔多瓦的新手。我已经完成了Cordova 3.5.0的安装过程,你好世界计划对我来说很好。但是,当我尝试使用一些Cordova API之类的Alert时,它会在logcat中给出以下错误:
07-18 03:42:07.060: D/CordovaActivity(1183): onMessage(onPageStarted,file:///android_asset/www/index1.html)
07-18 03:42:08.170: D/CordovaWebViewClient(1183): onPageFinished(file:///android_asset/www/index1.html)
07-18 03:42:08.170: D/CordovaActivity(1183): onMessage(onPageFinished,file:///android_asset/www/index1.html)
07-18 03:42:08.410: D/CordovaActivity(1183): onMessage(spinner,stop)
07-18 03:42:10.180: D/CordovaActivity(1183): onMessage(spinner,stop)
07-18 03:42:12.740: D/CordovaLog(1183): file:///android_asset/www/index1.html: Line 28 : Uncaught TypeError: Cannot call method 'alert' of undefined
这是我的HelloWorld.java
package com.example.hello;
import org.apache.cordova.CordovaActivity;
import android.os.Bundle;
public class HelloWorld extends CordovaActivity
{
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//super.init();
// Set by <content src="index.html" /> in config.xml
//super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html");
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("file:///android_asset/www/index1.html", 5000);
}
}
这是我的index1.html:
<!DOCTYPE html>
<html>
<head>
<title>Notification Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
// Empty
}
// alert dialog dismissed
function alertDismissed() {
// do something
}
// Show a custom alertDismissed
//
function showAlert() {
navigator.notification.alert(
'You are the winner!', // message
alertDismissed, // callback
'Game Over', // title
'Done' // buttonName
);
}
</script>
</head>
<body>
<p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
</body>
</html>
我的清单文件:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="com.example.hello" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:launchMode="singleTop" android:name="HelloWorld" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
</manifest>
my config.xml file:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<preference name="loglevel" value="DEBUG" />
<preference name="AndroidLaunchMode" value="singleTop" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="Notification">
<param name="android-package" value="org.apache.cordova.Notification" />
</feature>
<name>HelloWorld</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index1.html" />
<access origin="*" />
</widget>
请建议如何解决此问题。
答案 0 :(得分:2)
您需要先添加对话框插件。 您可以使用以下命令添加它。
cordova plugin add org.apache.cordova.dialogs