我是PhoneGap的新手,我的navigator.notification.alert不会工作。 我认为这是因为我没有导入navigator.notification.alert插件,但我不知道如何在我的设置中。 这是我的config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "id"
versionCode=""
version = "0.90">
<name>Name</name>
<description> Description </description>
<author href="" email="">
</author>
<preference name="phonegap-version" value="cli-5.1.1" />
<preference name="orientation" value="portrait" />
<preference name="fullscreen" value="false" />
<preference name="target-device" value="universal" />
<preference name="webviewbounce" value="true" />
<preference name="prerendered-icon" value="true" />
<preference name="stay-in-webview" value="true" />
<preference name="ios-statusbarstyle" value="default" />
<preference name="detect-data-types" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="show-splash-screen-spinner" value="true" />
<preference name="auto-hide-splash-screen" value="true" />
<preference name="EnableViewportScale" value="true" />
<preference name="MediaPlaybackRequiresUserAction" value="false" />
<preference name="AllowInlineMediaPlayback" value="false" />
<preference name="BackupWebStorage" value="cloud" />
<preference name="TopActivityIndicator" value="gray" />
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
<preference name="HideKeyboardFormAccessoryBar" value="false" />
<preference name="SuppressesIncrementalRendering" value="false" />
<preference name="android-minSdkVersion" value="7" />
<preference name="android-installLocation" value="internalOnly" />
<preference name="SplashScreenDelay" value="5000" />
<preference name="ErrorUrl" value=""/>
<preference name="BackgroundColor" value="0x000000"/>
<preference name="KeepRunning" value="true"/>
<preference name="DisallowOverscroll" value="false"/>
<preference name="LoadingDialog" value=","/>
<preference name="LoadUrlTimeoutValue" value="20000" />
<preference name="disable-cursor" value="false" />
<gap:platform name="ios" />
<gap:platform name="android" />
<feature name="http://api.phonegap.com/1.0/notification"/>
<gap:plugin name="org.apache.cordova.Notification" />
</widget>
这是我的index.html:
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="css/jquery.mobile- 1.4.5.min.css" />
<link rel="stylesheet" type="text/css" href="css/css.css" />
<script type="text/javascript" src="js/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript" src="phonegap.js"></script>
</head>
<body onload="pageLoaded();">
<div id="content">
<script type="text/javascript">
function onclick1() {
navigator.notification.alert("Hi");
}
</script>
<p><input id="Button1" type="button" value="Test 1" onclick="return onclick1()" /></p>
<script type="text/javascript">
function testAlert2() {
navigator.notification.alert(
"message",
"title",
"OK",
{
onClose: function(buttonIndex) {
if (buttonIndex == 0)
//doSomething();
}
}
);
}
</script>
<p><a href="javascript: testAlert2();">Test 2</a></p>
<script type="text/javascript">
function Alert3() {
navigator.notification.alert("message", function() {}, "title", "OK");
}
</script>
<p><a href="javascript: Alert3();">Test 3</a></p>
<script type="text/javascript">
function Alert4() {
navigator.notification.alert('Title','Message','Button message');
}
</script>
<p><a href="javascript: Alert4();">Test 4</a></p>
</div>
</div>
</body>
</html>
在我的config.xml中,如何导入navigator.notification.alert? 这些警报都不起作用。
答案 0 :(得分:1)
添加插件:
cordova plugin add org.apache.cordova.dialogs
在您的config.xml中:
<feature name="Notification">
<param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>
示例:
<!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>