diff --git a/plugin.xml b/plugin.xml index bad3973..b9be1f1 100644 --- a/plugin.xml +++ b/plugin.xml @@ -10,12 +10,14 @@ JPush,push Apache 2.0 License + + - + @@ -42,11 +44,18 @@ - + + + $API_KEY + + + + + @@ -152,16 +161,16 @@ - + - + - \ No newline at end of file + diff --git a/scripts/android-install.js b/scripts/android-install.js new file mode 100644 index 0000000..ae9d513 --- /dev/null +++ b/scripts/android-install.js @@ -0,0 +1,48 @@ +#!/usr/bin/env node + +module.exports = function (context) { + var path = context.requireCordovaModule('path'), + fs = context.requireCordovaModule('fs'), + shell = context.requireCordovaModule('shelljs'), + projectRoot = context.opts.projectRoot, + ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser'), + config = new ConfigParser(path.join(context.opts.projectRoot, "config.xml")), + packageName = config.android_packageName() || config.packageName(); + + console.info("Running android-install.Hook: " + context.hook + ", Package: " + packageName + ", Path: " + projectRoot + "."); + + if (!packageName) { + console.error("Package name could not be found!"); + return ; + } + + // android platform available? + if (context.opts.cordova.platforms.indexOf("android") === -1) { + console.info("Android platform has not been added."); + return ; + } + + var targetDir = path.join(projectRoot, "platforms", "android", "src", "cn", "jpush", "phonegap"); + targetFile = path.join(targetDir, "JPushPlugin.java"); + console.log(targetDir); + + if (['after_plugin_add', 'after_plugin_install', 'after_platform_add'].indexOf(context.hook) === -1) { + // remove it? + try { + fs.unlinkSync(targetFile); + } catch (err) {} + } else { + // create directory + shell.mkdir('-p', targetDir); + + // sync the content + fs.readFile(path.join(context.opts.plugin.dir, 'src', 'android', 'JPushPlugin.java'), {encoding: 'utf-8'}, function (err, data) { + if (err) { + throw err; + } + + data = data.replace(/^import __PACKAGE_NAME__.R;/m, 'import ' + packageName + '.R;'); + fs.writeFileSync(targetFile, data); + }); + } +}; diff --git a/src/android/JPushPlugin.java b/src/android/JPushPlugin.java index b669b65..d71db60 100644 --- a/src/android/JPushPlugin.java +++ b/src/android/JPushPlugin.java @@ -19,7 +19,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.Map.Entry; -import your.package.name.R; +import __PACKAGE_NAME__.R; import cn.jpush.android.api.BasicPushNotificationBuilder; import cn.jpush.android.api.CustomPushNotificationBuilder; @@ -46,6 +46,7 @@ public class JPushPlugin extends CordovaPlugin { "setLatestNotificationNum", "setPushTime", "clearAllNotification", + "clearNotificationById", "addLocalNotification", "removeLocalNotification", "clearLocalNotifications", diff --git a/src/ios/PushConfig.plist b/src/ios/PushConfig.plist index 5d8a46d..4f5394d 100644 --- a/src/ios/PushConfig.plist +++ b/src/ios/PushConfig.plist @@ -1,10 +1,10 @@ - - APP_KEY - 7d431e42dfa6a6d693ac2d04 - CHANNEL - Subscription - + + APP_KEY + + CHANNEL + Subscription + diff --git a/www/JPushPlugin.js b/www/JPushPlugin.js index a830f5e..3937c42 100644 --- a/www/JPushPlugin.js +++ b/www/JPushPlugin.js @@ -253,6 +253,13 @@ JPushPlugin.prototype.clearAllNotification = function(){ } } +JPushPlugin.prototype.clearNotificationById = function(notificationId){ + if(device.platform == "Android") { + data=[] + this.call_native("clearNotificationById",[notificationId],null); + } +} + JPushPlugin.prototype.setLatestNotificationNum = function(num){ if(device.platform == "Android") { this.call_native("setLatestNotificationNum",[num],null);