PhoneGap API介绍:Notification

网友投稿 302 2023-05-12

方法

notification.alert notification.confirm notification.beep notification.vibrate

 notification.alert

显示一个定制的警告或对话框。
复制navigator.notification.alert(message, alertCallback, [title], [buttonName]);  1.
message:对话框信息。(字符串类型) alertCallback:当警告对话框被忽略时调用的回调函数。(函数类型) title:对话框标题。(字符串类型)(可选项,默认值为“Alert”) buttonName:按钮名称(字符串类型)(可选项,默认值为“OK”)

说明

大多数PhoneGap使用本地对话框实现该功能。然而,一些平台只是简单的使用浏览器的alert函数,而这种方法通常是不能定制的。

支持的平台

Android BlackBerry (OS 4.6) BlackBerry WebWorks (OS 5.0或更高版本) iPhone

简单的范例

复制// Android / BlackBerry WebWorks (OS 5.0 and higher) // iPhone function alertDismissed() {      // 进行处理 navigator.notification.alert(      You are the winner!,  // 显示信息        alertDismissed,         // 警告被忽视的回调函数        Game Over,            // 标题        Done// 按钮名称 );  // BlackBerry (OS 4.6) // webOS navigator.notification.alert(You are the winner!);  1.2.3.4.5.6.7.8.9.10.11.12.13.14.

完整的范例

复制<!DOCTYPE html> <html> <head> <title>Notification Example</title> <scripttype="text/javascript"charset="utf-8"src="phonegap.js"></script> <scripttype="text/javascript"charset="utf-8">     // 等待加载PhoneGap      document.addEventListener("deviceready", onDeviceReady, false);      // PhoneGap加载完毕      function onDeviceReady() {          // 空      }      // 警告对话框被忽视      function alertDismissed() {          // 进行处理      }      // 显示一个定制的警告框      function showAlert() {          navigator.notification.alert(              You are the winner!,  // 显示信息              alertDismissed,         // 警告被忽视的回调函数              Game Over,            // 标题              Done                  // 按钮名称          );      }  </script> </head> <body>     <p><ahref="#"onclick="showConfirm(); return false;">Show Confirm</a></p> </body> </html> 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.

notification.confirm

显示一个可定制的确认对话框。
复制navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels]);  1.
message:对话框信息。(字符串类型) confirmCallback:按下按钮后触发的回调函数,返回按下按钮的索引(1、2或3)。(函数类型) title:对话框标题。(字符串类型)(可选项,默认值为“Confirm”) buttonLabels:逗号分隔的按钮标签字符串。(字符串类型)(可选项,默认值为“OK、Cancel”)

说明

notification.confirm函数显示一个定制性比浏览器的confirm函数更好的本地对话框。

支持的平台

Android BlackBerry WebWorks (OS 5.0或更高版本) iPhone

简单的范例

复制// 处理确认对话框返回的结果 function onConfirm(button) {      alert(You selected button  + button);  // 显示一个定制的确认对话框 function showConfirm() {         navigator.notification.confirm(             You are the winner!,  // 显示信息            onConfirm,              // 按下按钮后触发的回调函数,返回按下按钮的索引            Game Over,            // 标题            Restart,Exit// 按钮标签        );   }  1.2.3.4.5.6.7.8.9.10.11.12.13.14.

完整的范例

复制<!DOCTYPE html> <html> <head> <title>Notification Example</title> <scripttype="text/javascript"charset="utf-8"src="phonegap.js"></script> <scripttype="text/javascript"charset="utf-8">     // 等待加载PhoneGap      document.addEventListener("deviceready", onDeviceReady, false);      // PhoneGap加载完毕      function onDeviceReady() {          // 空      }      // 处理确认对话框返回的结果      function onConfirm(button) {          alert(You selected button  + button);      }      // 显示一个定制的确认对话框      function showConfirm() {          navigator.notification.confirm(              You are the winner!,  // 显示信息              onConfirm,              // 按下按钮后触发的回调函数,返回按下按钮的索引                  Game Over,            // 标题              Restart,Exit          // 按钮标签          );      }  </script> </head> <body>     <p><ahref="#"onclick="showConfirm(); return false;">Show Confirm</a></p> </body> </html> 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.

notification.beep

设备将发出蜂鸣声。
复制navigator.notification.beep(times);  1.
times:蜂鸣声的重复次数。(数字类型)

支持的平台

Android BlackBerry (OS 4.6) BlackBerry WebWorks (OS 5.0或更高版本) iPhone

简单的范例

复制// 蜂鸣2次! navigator.notification.beep(2);  1.2.

完整的范例

复制<!DOCTYPE html> <html> <head> <title>Notification Example</title> <scripttype="text/javascript"charset="utf-8"src="phonegap.js"></script> <scripttype="text/javascript"charset="utf-8"> // 等待加载PhoneGap  document.addEventListener("deviceready", onDeviceReady, false);  // PhoneGap加载完毕  function onDeviceReady() {         // 空  // 显示一个定制的警告框  function showAlert() {         navigator.notification.alert(             You are the winner!,  // 显示信息             Game Over,            // 标题             Done                  // 按钮名称         );  // 蜂鸣三次  function playBeep() {         navigator.notification.beep(3);  // 震动两秒  function vibrate() {         navigator.notification.vibrate(2000);  </script> </head> <body>     <p><ahref="#"onclick="showAlert(); return false;">Show Alert</a></p>     <p><ahref="#"onclick="playBeep(); return false;">Play Beep</a></p>     <p><ahref="#"onclick="vibrate(); return false;">Vibrate</a></p> </body> </html> 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.

Android的特异情况

Androids会播放在“设置/音效及显示”面板中指定的默认“通知铃声”。

iPhone的特异情况

忽略蜂鸣次数参数。 iPhone没有本地的蜂鸣API。 PhoneGap通过多媒体API播放音频文件来实现蜂鸣。 用户必须提供一个包含所需的蜂鸣声的文件。 此文件播放时长必须短于30秒,位于www/root,并且必须命名为beep.wav。

notification.vibrate

使设备震动指定的时长。
复制navigator.notification.vibrate(milliseconds);  1.
time:以毫秒为单位的设备震动时长,1000毫秒为1秒。(数字类型)

支持的平台

Android BlackBerry (OS 4.6) BlackBerry WebWorks (OS 5.0或更高版本) iPhone

简单的范例

复制// 震动2.5秒 navigator.notification.vibrate(2500);  1.2.

完整的范例

复制<!DOCTYPE html>  <html>  <head>      <title>Notification Example</title>  <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>  <script type="text/javascript" charset="utf-8" // 等待加载PhoneGap document.addEventListener("deviceready", onDeviceReady, false);  // PhoneGap加载完毕 function onDeviceReady() {         //空 // 显示定制警告框 function showAlert() {         navigator.notification.alert(             You are the winner!,  // 显示信息            Game Over,            // 标题            Done// 按钮名称        );  // 响三次 function playBeep() {         navigator.notification.beep(3);  // 震动两秒 function vibrate() {         navigator.notification.vibrate(2000);  </script>  </head>  <body>      <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>      <p><a href="#" onclick="playBeep(); return false;">Play Beep</a></p>      <p><a href="#" onclick="vibrate(); return false;">Vibrate</a></p>  </body>  </html>  1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.

iPhone的特异情况

time:忽略时长参数,震动时长为预先设定值。

简单的范例

复制navigator.notification.vibrate();  navigator.notification.vibrate(2500);   // 2500被忽略掉 1.2.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java时间类库Timer的使用方法与实例详解
下一篇:Java汉字转拼音类库Pinyin4j详细使用方法与实例
相关文章

 发表评论

暂时没有评论,来抢沙发吧~