Merge pull request #387 from jpush/dev

Dev
This commit is contained in:
JoshLipan 2018-12-20 16:27:34 +08:00 committed by GitHub
commit b2e818e88d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 35 deletions

View File

@ -42,6 +42,27 @@
cordova plugin add Your_Plugin_Path --variable APP_KEY=your_jpush_appkey 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 ### Ionic
如果使用了 Ionic可以再安装 @jiguang-ionic/jpush 包,适配 ionic-native 如果使用了 Ionic可以再安装 @jiguang-ionic/jpush 包,适配 ionic-native

View File

@ -1,6 +1,6 @@
{ {
"name": "jpush-phonegap-plugin", "name": "jpush-phonegap-plugin",
"version": "3.5.0", "version": "3.6.0",
"description": "JPush for cordova plugin", "description": "JPush for cordova plugin",
"cordova": { "cordova": {
"id": "jpush-phonegap-plugin", "id": "jpush-phonegap-plugin",

View File

@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
id="jpush-phonegap-plugin" id="jpush-phonegap-plugin"
version="3.5.0"> version="3.6.0">
<name>JPush</name> <name>JPush</name>
<description>JPush for cordova plugin</description> <description>JPush for cordova plugin</description>
@ -11,6 +11,7 @@
<license>MIT License</license> <license>MIT License</license>
<preference name="APP_KEY" /> <preference name="APP_KEY" />
<preference name="CHANNEL" default="developer-default" />
<engines> <engines>
<engine name="cordova" version=">=3.0" /> <engine name="cordova" version=">=3.0" />
@ -212,11 +213,11 @@
<!-- Required. Enable it you can get statistics data with channel --> <!-- Required. Enable it you can get statistics data with channel -->
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" /> <meta-data android:name="JPUSH_CHANNEL" android:value="$CHANNEL" />
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" /> <meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
</config-file> </config-file>
<lib-file src="src/android/libs/jpush-android-3.1.7.jar" /> <lib-file src="src/android/libs/jpush-android-3.1.8.jar" />
<source-file src="src/android/JPushReceiver.java" target-dir="src/cn/jiguang/cordova/push" /> <source-file src="src/android/JPushReceiver.java" target-dir="src/cn/jiguang/cordova/push" />
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jiguang/cordova/push" /> <source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jiguang/cordova/push" />

View File

@ -1,8 +1,8 @@
package cn.jiguang.cordova.push; package cn.jiguang.cordova.push;
import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.app.AppOpsManager; import android.app.AppOpsManager;
import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.os.Build; import android.os.Build;
@ -20,22 +20,17 @@ import org.json.JSONObject;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; 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.BasicPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback; import cn.jpush.android.api.TagAliasCallback;
import cn.jpush.android.data.JPushLocalNotification; import cn.jpush.android.data.JPushLocalNotification;
import cn.jpush.android.service.JPushMessageReceiver;
public class JPushPlugin extends CordovaPlugin { public class JPushPlugin extends CordovaPlugin {
@ -673,35 +668,42 @@ public class JPushPlugin extends CordovaPlugin {
} }
}; };
@TargetApi(Build.VERSION_CODES.KITKAT)
private boolean hasPermission(String appOpsServiceId) { private boolean hasPermission(String appOpsServiceId) {
Context context = cordova.getActivity().getApplicationContext(); Context context = cordova.getActivity().getApplicationContext();
AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); if (Build.VERSION.SDK_INT >= 24) {
ApplicationInfo appInfo = context.getApplicationInfo(); 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(); String pkg = context.getPackageName();
int uid = appInfo.uid; int uid = appInfo.uid;
Class appOpsClazz; Class appOpsClazz;
try { try {
appOpsClazz = Class.forName(AppOpsManager.class.getName()); appOpsClazz = Class.forName(AppOpsManager.class.getName());
Method checkOpNoThrowMethod = appOpsClazz.getMethod("checkOpNoThrow", Integer.TYPE, Integer.TYPE, Method checkOpNoThrowMethod = appOpsClazz.getMethod("checkOpNoThrow", Integer.TYPE, Integer.TYPE,
String.class); String.class);
Field opValue = appOpsClazz.getDeclaredField(appOpsServiceId); Field opValue = appOpsClazz.getDeclaredField(appOpsServiceId);
int value = opValue.getInt(Integer.class); int value = opValue.getInt(Integer.class);
Object result = checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg); Object result = checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg);
return Integer.parseInt(result.toString()) == AppOpsManager.MODE_ALLOWED; return Integer.parseInt(result.toString()) == AppOpsManager.MODE_ALLOWED;
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
e.printStackTrace(); e.printStackTrace();
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
}
} }
return true;
return false;
} }
} }

Binary file not shown.