step1.
請先請到以下的網址 下載 phonegap-plugins
https://github.com/phonegap/phonegap-plugins/tree/master/Android/LocalNotification
step2.
複製LocalNotification.js 到你的 www資料夾內
並且在index.html 中把他加入進去
<script type="text/javascript" charset="utf-8" src="js/LocalNotification.js"></script>
step3.
創造一個 package 命名為com.phonegap.plugin.localnotification
將
AlarmHelper
AlarmOptions
AlarmReceiver
AlarmRestoreOnBoot
LocalNotification
以上的java檔加入
step4.
到AlarmReceiver 來修改錯誤
將R檔選擇到你自己目前的drawable.ic_launcher
final Notification notification = new Notification(R.drawable.ic_launcher, tickerText,
System.currentTimeMillis());
到LocalNotification來修改錯誤
這已經是舊版的
//import com.phonegap.api.Plugin;
//import com.phonegap.api.PluginResult;
改為新版的
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
step5.
Update your res/xml/plugins.xml file
加入以下的code
<plugin name="LocalNotification" value="com.phonegap.plugin.localnotification.LocalNotification" />
step6.AndroidManifest.xml 檔案裡面 找出<application>標籤
加入以下的code
<receiver android:name="com.phonegap.plugin.localnotification.AlarmReceiver" >
</receiver>
<receiver android:name="com.phonegap.plugin.localnotification.AlarmRestoreOnBoot" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
step7.
html 的使用方法
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" src="cordova_2.9.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" charset="utf-8" src="js/LocalNotification.js"></script>
<title>Hello World</title>
<script type="text/javascript">
document.addEventListener("deviceready", appReady, false);
function appReady() {
console.log("Device ready");
if (typeof plugins !== "undefined") {
plugins.localNotification
.add({
date : new Date(),
message : "Phonegap - Local Notification\r\nSubtitle comes after linebreak",
ticker : "This is a sample ticker text",
repeatDaily : false,
id : 4
});
}
}
document.addEventListener("deviceready", appReady, false);
</script>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript">
//app.initialize();
</script>
</body>
</html>
0 意見:
張貼留言