Javascript cordova中未定义警报
我是科尔多瓦的新手。我已经完成了Cordova 3.5.0的安装过程,hello World程序对我来说运行良好。但当我试图使用一些Cordova API的类似警报时,它在logcat中给出了以下错误:Javascript cordova中未定义警报,javascript,android,cordova,Javascript,Android,Cordova,我是科尔多瓦的新手。我已经完成了Cordova 3.5.0的安装过程,hello World程序对我来说运行良好。但当我试图使用一些Cordova API的类似警报时,它在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/CordovaWebViewClie
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);
}
}
package com.example.hello;
导入org.apache.cordova.cordova活动;
导入android.os.Bundle;
公共类HelloWorld扩展了CordovaActivity
{
@抑制警告(“弃用”)
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//super.init();
//在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>
通知示例
//等待加载设备API库
//
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
//设备API可用
//
函数ondevicerady(){
//空的
}
//警报对话框已关闭
函数{
//做点什么
}
//显示自定义警报
//
函数showAlert(){
navigator.notification.alert(
“你是赢家!”,//留言
AlertDisabled,//回调
“游戏结束了”,//标题
'完成'//buttonName
);
}
我的清单文件:
<?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>
my config.xml文件:
你好世界
响应deviceready事件的Apache Cordova应用程序示例。
阿帕奇科尔多瓦团队
请建议如何解决此问题。您需要先添加对话框插件。 您可以使用下面的命令添加它
cordova plugin add org.apache.cordova.dialogs
你添加了通知插件了吗?有关文档,请参阅。我无法执行此步骤:cordova plugin add它给了我以下错误:F:\cordova\cordova Projects\hello>cordova plugin add Fetching plugin“”via git clone错误:“git”命令行工具未安装:确保在您的路径上可以访问它。您必须从下载git,并确保选中该选项“从windows命令提示符使用git”。