diff --git a/README.md b/README.md index 890e681..5926b8e 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,27 @@ ```shell cordova plugin add Your_Plugin_Path --variable APP_KEY=your_jpush_appkey ``` + + +### 参数 + + - APP_KEY: 必须设置,JPush 上注册的包名对应的 Appkey + + ```shell + --variable APP_KEY=your_jpush_appkey + ``` + + - CHANNEL: 可以不设置,v3.6.0+ 版本开始支持(Android Only),方便开发者统计 APK 分发渠道,默认为 developer-default. + + ```shell + --variable CHANNEL=your_channel + ``` + + - 同时动态配置 APP_KEY 和 CHANNEL 示例 + + ```shell + cordova plugin add jpush-phonegap-plugin --variable APP_KEY=your_jpush_appkey --variable CHANNEL=your_channel + ``` ### Ionic diff --git a/package.json b/package.json index 63bf9fe..97b042c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpush-phonegap-plugin", - "version": "3.5.0", + "version": "3.6.0", "description": "JPush for cordova plugin", "cordova": { "id": "jpush-phonegap-plugin", diff --git a/plugin.xml b/plugin.xml index f66d8ad..14fddf1 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="3.6.0"> JPush JPush for cordova plugin @@ -11,6 +11,7 @@ MIT License + @@ -212,11 +213,11 @@ - + - + diff --git a/src/android/JPushPlugin.java b/src/android/JPushPlugin.java index b58b893..6300443 100644 --- a/src/android/JPushPlugin.java +++ b/src/android/JPushPlugin.java @@ -1,8 +1,8 @@ package cn.jiguang.cordova.push; -import android.annotation.TargetApi; import android.app.Activity; import android.app.AppOpsManager; +import android.app.NotificationManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.os.Build; @@ -20,22 +20,17 @@ import org.json.JSONObject; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import cn.jpush.android.api.BasicPushNotificationBuilder; import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.TagAliasCallback; import cn.jpush.android.data.JPushLocalNotification; -import cn.jpush.android.service.JPushMessageReceiver; public class JPushPlugin extends CordovaPlugin { @@ -673,35 +668,42 @@ public class JPushPlugin extends CordovaPlugin { } }; - @TargetApi(Build.VERSION_CODES.KITKAT) private boolean hasPermission(String appOpsServiceId) { + Context context = cordova.getActivity().getApplicationContext(); - AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); - ApplicationInfo appInfo = context.getApplicationInfo(); + if (Build.VERSION.SDK_INT >= 24) { + NotificationManager mNotificationManager = (NotificationManager) context + .getSystemService(Context.NOTIFICATION_SERVICE); + return mNotificationManager.areNotificationsEnabled(); + } else { + AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); + ApplicationInfo appInfo = context.getApplicationInfo(); - String pkg = context.getPackageName(); - int uid = appInfo.uid; - Class appOpsClazz; + String pkg = context.getPackageName(); + int uid = appInfo.uid; + Class appOpsClazz; - try { - appOpsClazz = Class.forName(AppOpsManager.class.getName()); - Method checkOpNoThrowMethod = appOpsClazz.getMethod("checkOpNoThrow", Integer.TYPE, Integer.TYPE, - String.class); - Field opValue = appOpsClazz.getDeclaredField(appOpsServiceId); - int value = opValue.getInt(Integer.class); - Object result = checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg); - return Integer.parseInt(result.toString()) == AppOpsManager.MODE_ALLOWED; - } catch (InvocationTargetException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); + try { + appOpsClazz = Class.forName(AppOpsManager.class.getName()); + Method checkOpNoThrowMethod = appOpsClazz.getMethod("checkOpNoThrow", Integer.TYPE, Integer.TYPE, + String.class); + Field opValue = appOpsClazz.getDeclaredField(appOpsServiceId); + int value = opValue.getInt(Integer.class); + Object result = checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg); + return Integer.parseInt(result.toString()) == AppOpsManager.MODE_ALLOWED; + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } } - return true; + + return false; } } diff --git a/src/android/libs/jpush-android-3.1.7.jar b/src/android/libs/jpush-android-3.1.7.jar deleted file mode 100755 index bf0a170..0000000 Binary files a/src/android/libs/jpush-android-3.1.7.jar and /dev/null differ diff --git a/src/android/libs/jpush-android-3.1.8.jar b/src/android/libs/jpush-android-3.1.8.jar new file mode 100755 index 0000000..5354f37 Binary files /dev/null and b/src/android/libs/jpush-android-3.1.8.jar differ