diff --git a/plugin.xml b/plugin.xml index 71ffd87..3a550fb 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ JPush Plugin @@ -16,8 +16,10 @@ + + - + @@ -58,6 +60,8 @@ + + @@ -186,7 +190,6 @@ - diff --git a/src/android/JPushPlugin.java b/src/android/JPushPlugin.java index 727f799..ef65ef1 100644 --- a/src/android/JPushPlugin.java +++ b/src/android/JPushPlugin.java @@ -2,6 +2,7 @@ package cn.jpush.phonegap; import android.app.Activity; import android.content.Context; +import android.support.v4.app.NotificationManagerCompat; import android.text.TextUtils; import android.util.Log; @@ -26,7 +27,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import cn.jpush.android.api.BasicPushNotificationBuilder; -import cn.jpush.android.api.CustomPushNotificationBuilder; import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.TagAliasCallback; import cn.jpush.android.data.JPushLocalNotification; @@ -35,6 +35,7 @@ public class JPushPlugin extends CordovaPlugin { private final static List methodList = Arrays.asList( "addLocalNotification", + "areNotificationEnabled", "clearAllNotification", "clearLocalNotifications", "clearNotificationById", @@ -312,6 +313,18 @@ public class JPushPlugin extends CordovaPlugin { } } + void areNotificationEnabled(JSONArray data, final CallbackContext callback) { + NotificationManagerCompat nmc = NotificationManagerCompat.from( + cordova.getActivity().getApplicationContext()); + int isEnabled; + if (nmc.areNotificationsEnabled()) { + isEnabled = 1; + } else { + isEnabled = 0; + } + callback.success(isEnabled); + } + void setLatestNotificationNum(JSONArray data, CallbackContext callbackContext) { int num = -1; try { diff --git a/www/JPushPlugin.js b/www/JPushPlugin.js index b426200..3689fab 100644 --- a/www/JPushPlugin.js +++ b/www/JPushPlugin.js @@ -210,9 +210,20 @@ JPushPlugin.prototype.getApplicationIconBadgeNumber = function(callback) { } } + +// 判断系统设置中是否对本应用启用通知。 +// iOS: 返回值如果大于 0,代表通知开启;0: 通知关闭。 +// UIRemoteNotificationTypeNone = 0, +// UIRemoteNotificationTypeBadge = 1 << 0, +// UIRemoteNotificationTypeSound = 1 << 1, +// UIRemoteNotificationTypeAlert = 1 << 2, +// UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3, +// Android: 返回值 1 代表通知启用、0: 通知关闭。 JPushPlugin.prototype.getUserNotificationSettings = function(callback) { if(this.isPlatformIOS()) { this.call_native("getUserNotificationSettings", [], callback); + } else if (device.platform == "Android") { + this.call_native("areNotificationEnabled", [], callback); } }