android增加本地通知

This commit is contained in:
zhangqinghe 2015-01-15 10:31:43 +08:00
parent 5a33f0c6e2
commit 3d74b92952
3 changed files with 66 additions and 3 deletions

View File

@ -38,8 +38,16 @@
}
var initiateUI = function(){
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
try{
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
// var extras={"name":"json"};
// window.plugins.jPushPlugin.addLocalNotification(1,"hh","ln",1111,1000*60,extras);
// window.plugins.jPushPlugin.removeLocalNotification(1111);
// window.plugins.jPushPlugin.clearLocalNotifications();
}
catch(exception){
console.log(exception);
}
//test android interface
//window.plugins.jPushPlugin.stopPush()

View File

@ -44,7 +44,10 @@ public class JPushPlugin extends CordovaPlugin {
"isPushStopped",
"setLatestNotificationNum",
"setPushTime",
"clearAllNotification");
"clearAllNotification",
"addLocalNotification",
"removeLocalNotification",
"clearLocalNotifications");
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
private static JPushPlugin instance;
@ -373,6 +376,41 @@ public class JPushPlugin extends CordovaPlugin {
callbackContext.error("error id");
}
}
void addLocalNotification(JSONArray data,
CallbackContext callbackContext) throws JSONException{
//builderId,content,title,notificaitonID,broadcastTime,extras
int builderId=data.getInt(0);
String content =data.getString(1);
String title = data.getString(2);
int notificationID= data.getInt(3);
int broadcastTime=data.getInt(4);
JSONObject extras=data.getJSONObject(5);
JPushLocalNotification ln = new JPushLocalNotification();
ln.setBuilderId(builderId);
ln.setContent(content);
ln.setTitle(title);
ln.setNotificationId(notificationID) ;
ln.setBroadcastTime(System.currentTimeMillis() + broadcastTime);
ln.setExtras(extras.toString()) ;
JPushInterface.addLocalNotification(this.cordova.getActivity(), ln);
}
void removeLocalNotification(JSONArray data,
CallbackContext callbackContext) throws JSONException{
int notificationID=data.getInt(0);
JPushInterface.removeLocalNotification(this.cordova.getActivity(),notificationID);
}
void clearLocalNotifications(JSONArray data,
CallbackContext callbackContext){
JPushInterface.clearLocalNotifications(this.cordova.getActivity());
}
private final TagAliasCallback mTagWithAliasCallback = new TagAliasCallback() {

View File

@ -223,6 +223,23 @@ JPushPlugin.prototype.setDebugMode = function(mode){
this.call_native("setDebugMode",[mode],null);
}
}
JPushPlugin.prototype.addLocalNotification = function(builderId,content,title,notificaitonID,broadcastTime,extras){
if(device.platform == "Android") {
data=[builderId,content,title,notificaitonID,broadcastTime,extras];
this.call_native("addLocalNotification",data,null);
}
}
JPushPlugin.prototype.removeLocalNotification = function(notificationID){
if(device.platform == "Android") {
this.call_native("removeLocalNotification",[notificationID],null);
}
}
JPushPlugin.prototype.clearLocalNotifications = function(){
if(device.platform == "Android") {
data=[]
this.call_native("clearLocalNotifications",data,null);
}
}
//iOS single