mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-01-31 22:42:51 +08:00
Merge remote-tracking branch 'refs/remotes/origin/dev'
This commit is contained in:
commit
44345d9753
@ -2,7 +2,7 @@
|
||||
|
||||
[![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin)
|
||||
[![QQ Group](https://img.shields.io/badge/QQ%20Group-413602425-red.svg)]()
|
||||
[![release](https://img.shields.io/badge/release-2.2.1-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
||||
[![release](https://img.shields.io/badge/release-2.2.3-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
||||
[![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin)
|
||||
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
||||
|
||||
@ -75,8 +75,6 @@ Cordova CLI 的具体用法可参考 [Cordova CLI 官方文档](https://cordova.
|
||||
|
||||
解决方案:Eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
|
||||
|
||||
- 最新版插件依赖 android-support-v4:24.0.0 jar 包,需要及时更新 *Android Support Repository*。
|
||||
|
||||
### 2. iOS
|
||||
|
||||
- 收不到推送:
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jpush-phonegap-plugin",
|
||||
"version": "2.2.3",
|
||||
"version": "2.2.4",
|
||||
"description": "JPush for cordova plugin",
|
||||
"cordova": {
|
||||
"id": "jpush-phonegap-plugin",
|
||||
|
@ -58,8 +58,6 @@
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<framework src="com.android.support:support-v4:24.0.0" />
|
||||
|
||||
<config-file target="AndroidManifest.xml" parent="/manifest">
|
||||
<!-- Required 一些系统要求的权限,如访问网络等-->
|
||||
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" />
|
||||
|
@ -1,8 +1,11 @@
|
||||
package cn.jpush.phonegap;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@ -14,6 +17,8 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
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;
|
||||
@ -138,7 +143,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
|
||||
private static JSONObject getMessageObject(String message,
|
||||
Map<String, Object> extras) {
|
||||
Map<String, Object> extras) {
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("message", message);
|
||||
@ -172,7 +177,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
|
||||
private static JSONObject getNotificationObject(String title,
|
||||
String alert, Map<String, Object> extras) {
|
||||
String alert, Map<String, Object> extras) {
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("title", title);
|
||||
@ -180,7 +185,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
JSONObject jExtras = new JSONObject();
|
||||
for (Entry<String, Object> entry : extras.entrySet()) {
|
||||
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
|
||||
JSONObject jo = null;
|
||||
JSONObject jo;
|
||||
if (TextUtils.isEmpty((String) entry.getValue())) {
|
||||
jo = new JSONObject();
|
||||
} else {
|
||||
@ -222,7 +227,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
|
||||
static void transmitNotificationOpen(String title, String alert,
|
||||
Map<String, Object> extras) {
|
||||
Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
@ -240,7 +245,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
|
||||
static void transmitNotificationReceive(String title, String alert,
|
||||
Map<String, Object> extras) {
|
||||
Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
@ -259,7 +264,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
|
||||
@Override
|
||||
public boolean execute(final String action, final JSONArray data,
|
||||
final CallbackContext callbackContext) throws JSONException {
|
||||
final CallbackContext callbackContext) throws JSONException {
|
||||
if (!methodList.contains(action)) {
|
||||
return false;
|
||||
}
|
||||
@ -314,13 +319,11 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
|
||||
void areNotificationEnabled(JSONArray data, final CallbackContext callback) {
|
||||
NotificationManagerCompat nmc = NotificationManagerCompat.from(
|
||||
cordova.getActivity().getApplicationContext());
|
||||
int isEnabled;
|
||||
if (nmc.areNotificationsEnabled()) {
|
||||
if (hasPermission("OP_POST_NOTIFICATION")) {
|
||||
isEnabled = 1;
|
||||
} else {
|
||||
isEnabled = 0;
|
||||
isEnabled = 0;
|
||||
}
|
||||
callback.success(isEnabled);
|
||||
}
|
||||
@ -436,7 +439,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
|
||||
void setBasicPushNotificationBuilder(JSONArray data,
|
||||
CallbackContext callbackContext) {
|
||||
CallbackContext callbackContext) {
|
||||
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
|
||||
this.cordova.getActivity());
|
||||
builder.developerArg0 = "Basic builder 1";
|
||||
@ -450,22 +453,16 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义推送通知栏样式,需要自己实现具体代码。
|
||||
* http://docs.jiguang.cn/client/android_tutorials/#_11
|
||||
*/
|
||||
* 自定义推送通知栏样式,需要自己实现具体代码。
|
||||
* http://docs.jiguang.cn/client/android_tutorials/#_11
|
||||
*/
|
||||
void setCustomPushNotificationBuilder(JSONArray data,
|
||||
CallbackContext callbackContext) {
|
||||
CallbackContext callbackContext) {
|
||||
// CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
|
||||
// this.cordova.getActivity(), R.layout.test_notification_layout,
|
||||
// R.id.icon, R.id.title, R.id.text);
|
||||
// builder.developerArg0 = "Custom Builder 1";
|
||||
// JPushInterface.setPushNotificationBuilder(2, builder);
|
||||
// JSONObject obj = new JSONObject();
|
||||
// try {
|
||||
// obj.put("id", 2);
|
||||
// } catch (JSONException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// JPushInterface.setDefaultPushNotificationBuilder(builder);
|
||||
}
|
||||
|
||||
void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
|
||||
@ -600,4 +597,37 @@ 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();
|
||||
|
||||
String pkg = context.getPackageName();
|
||||
int uid = appInfo.uid;
|
||||
Class appOpsClazz = null;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user