gpt4 book ai didi

javascript - 警报在 Cordova 未定义

转载 作者:行者123 更新时间:2023-11-29 21:05:12 24 4
gpt4 key购买 nike

我是 Cordova 的新手。我已经完成了 Cordova 3.5.0 的安装过程,hello World 程序对我来说运行良好。但是当我尝试使用一些像 Alert 这样的 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/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>

我的 list 文件:

    <?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>

请建议如何解决此问题。

最佳答案

您需要先添加对话框插件。您可以使用以下命令添加它。

cordova plugin add org.apache.cordova.dialogs

关于javascript - 警报在 Cordova 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24819966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com