mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-05-07 19:12:58 +08:00
Merge remote-tracking branch 'refs/remotes/origin/dev'
This commit is contained in:
commit
44345d9753
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[](https://travis-ci.org/jpush/jpush-phonegap-plugin)
|
[](https://travis-ci.org/jpush/jpush-phonegap-plugin)
|
||||||
[]()
|
[]()
|
||||||
[](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
[](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
||||||
[](https://github.com/jpush/jpush-phonegap-plugin)
|
[](https://github.com/jpush/jpush-phonegap-plugin)
|
||||||
[](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
[](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。
|
解决方案:Eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
|
||||||
|
|
||||||
- 最新版插件依赖 android-support-v4:24.0.0 jar 包,需要及时更新 *Android Support Repository*。
|
|
||||||
|
|
||||||
### 2. iOS
|
### 2. iOS
|
||||||
|
|
||||||
- 收不到推送:
|
- 收不到推送:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "jpush-phonegap-plugin",
|
"name": "jpush-phonegap-plugin",
|
||||||
"version": "2.2.3",
|
"version": "2.2.4",
|
||||||
"description": "JPush for cordova plugin",
|
"description": "JPush for cordova plugin",
|
||||||
"cordova": {
|
"cordova": {
|
||||||
"id": "jpush-phonegap-plugin",
|
"id": "jpush-phonegap-plugin",
|
||||||
|
@ -58,8 +58,6 @@
|
|||||||
</feature>
|
</feature>
|
||||||
</config-file>
|
</config-file>
|
||||||
|
|
||||||
<framework src="com.android.support:support-v4:24.0.0" />
|
|
||||||
|
|
||||||
<config-file target="AndroidManifest.xml" parent="/manifest">
|
<config-file target="AndroidManifest.xml" parent="/manifest">
|
||||||
<!-- Required 一些系统要求的权限,如访问网络等-->
|
<!-- Required 一些系统要求的权限,如访问网络等-->
|
||||||
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" />
|
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" />
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package cn.jpush.phonegap;
|
package cn.jpush.phonegap;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AppOpsManager;
|
||||||
import android.content.Context;
|
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.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -14,6 +17,8 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -138,7 +143,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static JSONObject getMessageObject(String message,
|
private static JSONObject getMessageObject(String message,
|
||||||
Map<String, Object> extras) {
|
Map<String, Object> extras) {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
try {
|
try {
|
||||||
data.put("message", message);
|
data.put("message", message);
|
||||||
@ -172,7 +177,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static JSONObject getNotificationObject(String title,
|
private static JSONObject getNotificationObject(String title,
|
||||||
String alert, Map<String, Object> extras) {
|
String alert, Map<String, Object> extras) {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
try {
|
try {
|
||||||
data.put("title", title);
|
data.put("title", title);
|
||||||
@ -180,7 +185,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
JSONObject jExtras = new JSONObject();
|
JSONObject jExtras = new JSONObject();
|
||||||
for (Entry<String, Object> entry : extras.entrySet()) {
|
for (Entry<String, Object> entry : extras.entrySet()) {
|
||||||
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
|
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
|
||||||
JSONObject jo = null;
|
JSONObject jo;
|
||||||
if (TextUtils.isEmpty((String) entry.getValue())) {
|
if (TextUtils.isEmpty((String) entry.getValue())) {
|
||||||
jo = new JSONObject();
|
jo = new JSONObject();
|
||||||
} else {
|
} else {
|
||||||
@ -222,7 +227,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void transmitNotificationOpen(String title, String alert,
|
static void transmitNotificationOpen(String title, String alert,
|
||||||
Map<String, Object> extras) {
|
Map<String, Object> extras) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -240,7 +245,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void transmitNotificationReceive(String title, String alert,
|
static void transmitNotificationReceive(String title, String alert,
|
||||||
Map<String, Object> extras) {
|
Map<String, Object> extras) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -259,7 +264,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(final String action, final JSONArray data,
|
public boolean execute(final String action, final JSONArray data,
|
||||||
final CallbackContext callbackContext) throws JSONException {
|
final CallbackContext callbackContext) throws JSONException {
|
||||||
if (!methodList.contains(action)) {
|
if (!methodList.contains(action)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -314,13 +319,11 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void areNotificationEnabled(JSONArray data, final CallbackContext callback) {
|
void areNotificationEnabled(JSONArray data, final CallbackContext callback) {
|
||||||
NotificationManagerCompat nmc = NotificationManagerCompat.from(
|
|
||||||
cordova.getActivity().getApplicationContext());
|
|
||||||
int isEnabled;
|
int isEnabled;
|
||||||
if (nmc.areNotificationsEnabled()) {
|
if (hasPermission("OP_POST_NOTIFICATION")) {
|
||||||
isEnabled = 1;
|
isEnabled = 1;
|
||||||
} else {
|
} else {
|
||||||
isEnabled = 0;
|
isEnabled = 0;
|
||||||
}
|
}
|
||||||
callback.success(isEnabled);
|
callback.success(isEnabled);
|
||||||
}
|
}
|
||||||
@ -436,7 +439,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setBasicPushNotificationBuilder(JSONArray data,
|
void setBasicPushNotificationBuilder(JSONArray data,
|
||||||
CallbackContext callbackContext) {
|
CallbackContext callbackContext) {
|
||||||
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
|
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
|
||||||
this.cordova.getActivity());
|
this.cordova.getActivity());
|
||||||
builder.developerArg0 = "Basic builder 1";
|
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,
|
void setCustomPushNotificationBuilder(JSONArray data,
|
||||||
CallbackContext callbackContext) {
|
CallbackContext callbackContext) {
|
||||||
// CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
|
// CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
|
||||||
// this.cordova.getActivity(), R.layout.test_notification_layout,
|
// this.cordova.getActivity(), R.layout.test_notification_layout,
|
||||||
// R.id.icon, R.id.title, R.id.text);
|
// R.id.icon, R.id.title, R.id.text);
|
||||||
// builder.developerArg0 = "Custom Builder 1";
|
|
||||||
// JPushInterface.setPushNotificationBuilder(2, builder);
|
// JPushInterface.setPushNotificationBuilder(2, builder);
|
||||||
// JSONObject obj = new JSONObject();
|
// JPushInterface.setDefaultPushNotificationBuilder(builder);
|
||||||
// try {
|
|
||||||
// obj.put("id", 2);
|
|
||||||
// } catch (JSONException e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
|
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…
x
Reference in New Issue
Block a user