mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-01-31 14:32:51 +08:00
parent
b13aabe2bc
commit
5e44499ff5
@ -19,7 +19,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import __PACKAGE_NAME__.R;
|
import com.ljg.push.R;
|
||||||
|
|
||||||
import cn.jpush.android.api.BasicPushNotificationBuilder;
|
import cn.jpush.android.api.BasicPushNotificationBuilder;
|
||||||
import cn.jpush.android.api.CustomPushNotificationBuilder;
|
import cn.jpush.android.api.CustomPushNotificationBuilder;
|
||||||
@ -35,7 +35,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
"getRegistrationID",
|
"getRegistrationID",
|
||||||
"setTags",
|
"setTags",
|
||||||
"setTagsWithAlias",
|
"setTagsWithAlias",
|
||||||
"setAlias",
|
"setAlias",
|
||||||
"getNotification",
|
"getNotification",
|
||||||
"setBasicPushNotificationBuilder",
|
"setBasicPushNotificationBuilder",
|
||||||
"setCustomPushNotificationBuilder",
|
"setCustomPushNotificationBuilder",
|
||||||
@ -48,7 +48,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
"setLatestNotificationNum",
|
"setLatestNotificationNum",
|
||||||
"setPushTime",
|
"setPushTime",
|
||||||
"clearAllNotification",
|
"clearAllNotification",
|
||||||
"clearNotificationById",
|
"clearNotificationById",
|
||||||
"addLocalNotification",
|
"addLocalNotification",
|
||||||
"removeLocalNotification",
|
"removeLocalNotification",
|
||||||
"clearLocalNotifications",
|
"clearLocalNotifications",
|
||||||
@ -58,14 +58,16 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
|
|
||||||
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
||||||
private static JPushPlugin instance;
|
private static JPushPlugin instance;
|
||||||
private static String TAG = "Client JPushPlugin";
|
private static String TAG = "JPushPlugin";
|
||||||
|
|
||||||
|
private static boolean shouldCacheMsg = false;
|
||||||
|
|
||||||
public static boolean bOpenNotificationAlert = false;
|
|
||||||
public static String notificationAlert;
|
public static String notificationAlert;
|
||||||
public static Map<String, Object> notificationExtras=new HashMap<String, Object>();
|
public static Map<String, Object> notificationExtras=new HashMap<String, Object>();
|
||||||
public static String openNotificationAlert;
|
public static String openNotificationAlert;
|
||||||
public static Map<String, Object> openNotificationExtras=new HashMap<String, Object>();
|
public static Map<String, Object> openNotificationExtras=new HashMap<String, Object>();
|
||||||
|
|
||||||
|
|
||||||
public JPushPlugin() {
|
public JPushPlugin() {
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
@ -73,28 +75,44 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||||
super.initialize(cordova, webView);
|
super.initialize(cordova, webView);
|
||||||
//JPushInterface.setDebugMode(true);
|
|
||||||
|
Log.i(TAG, "---------------- initialize"+"-"+JPushPlugin.openNotificationAlert + "-" + JPushPlugin.notificationAlert);
|
||||||
//JPushPlugin.notificationAlert = alert;
|
|
||||||
//JPushPlugin.notificationExtras = extras;
|
shouldCacheMsg = false;
|
||||||
|
|
||||||
if(JPushPlugin.bOpenNotificationAlert){
|
|
||||||
|
|
||||||
JPushPlugin.bOpenNotificationAlert = false;
|
|
||||||
if(JPushPlugin.openNotificationAlert != null){
|
if(JPushPlugin.openNotificationAlert != null){
|
||||||
|
JPushPlugin.notificationAlert = null;
|
||||||
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
|
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
|
||||||
}
|
}
|
||||||
if(JPushPlugin.notificationAlert!=null){
|
if(JPushPlugin.notificationAlert!=null){
|
||||||
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
|
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//JPushInterface.init(cordova.getActivity().getApplicationContext());
|
//JPushInterface.init(cordova.getActivity().getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void onPause(boolean multitasking) {
|
||||||
|
Log.i(TAG, "---------------- onPause");
|
||||||
|
shouldCacheMsg = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onResume(boolean multitasking) {
|
||||||
|
shouldCacheMsg = false;
|
||||||
|
Log.i(TAG, "---------------- onResume"+"-"+JPushPlugin.openNotificationAlert + "-" + JPushPlugin.notificationAlert);
|
||||||
|
|
||||||
|
if(JPushPlugin.openNotificationAlert != null){
|
||||||
|
JPushPlugin.notificationAlert = null;
|
||||||
|
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
|
||||||
|
}
|
||||||
|
if(JPushPlugin.notificationAlert!=null){
|
||||||
|
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static JSONObject notificationObject(String message,
|
private static JSONObject notificationObject(String message,
|
||||||
Map<String, Object> extras) {
|
Map<String, Object> extras) {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
@ -169,19 +187,18 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(JPushPlugin.shouldCacheMsg){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i(TAG, "---------------- transmitOpen");
|
||||||
|
|
||||||
JSONObject data = openNotificationObject(alert, extras);
|
JSONObject data = openNotificationObject(alert, extras);
|
||||||
String js = String
|
String js = String
|
||||||
.format("window.plugins.jPushPlugin.openNotificationInAndroidCallback('%s');",
|
.format("window.plugins.jPushPlugin.openNotificationInAndroidCallback('%s');",
|
||||||
data.toString());
|
data.toString());
|
||||||
// {"alert":"ding",
|
|
||||||
// "extras":{
|
|
||||||
// "cn.jpush.android.MSG_ID":"1691785879",
|
|
||||||
// "app":"com.thi.pushtest",
|
|
||||||
// "cn.jpush.android.ALERT":"ding",
|
|
||||||
// "cn.jpush.android.EXTRA":{},
|
|
||||||
// "cn.jpush.android.PUSH_ID":"1691785879",
|
|
||||||
// "cn.jpush.android.NOTIFICATION_ID":1691785879,
|
|
||||||
// "cn.jpush.android.NOTIFICATION_TYPE":"0"}}
|
|
||||||
try {
|
try {
|
||||||
instance.webView.sendJavascript(js);
|
instance.webView.sendJavascript(js);
|
||||||
|
|
||||||
@ -194,24 +211,22 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
JPushPlugin.openNotificationAlert = null;
|
||||||
}
|
}
|
||||||
static void transmitReceive(String alert, Map<String, Object> extras) {
|
static void transmitReceive(String alert, Map<String, Object> extras) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(JPushPlugin.shouldCacheMsg){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
JSONObject data = openNotificationObject(alert, extras);
|
JSONObject data = openNotificationObject(alert, extras);
|
||||||
String js = String
|
String js = String
|
||||||
.format("window.plugins.jPushPlugin.receiveNotificationInAndroidCallback('%s');",
|
.format("window.plugins.jPushPlugin.receiveNotificationInAndroidCallback('%s');",
|
||||||
data.toString());
|
data.toString());
|
||||||
// {"alert":"ding",
|
|
||||||
// "extras":{
|
|
||||||
// "cn.jpush.android.MSG_ID":"1691785879",
|
|
||||||
// "app":"com.thi.pushtest",
|
|
||||||
// "cn.jpush.android.ALERT":"ding",
|
|
||||||
// "cn.jpush.android.EXTRA":{},
|
|
||||||
// "cn.jpush.android.PUSH_ID":"1691785879",
|
|
||||||
// "cn.jpush.android.NOTIFICATION_ID":1691785879,
|
|
||||||
// "cn.jpush.android.NOTIFICATION_TYPE":"0"}}
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
instance.webView.sendJavascript(js);
|
instance.webView.sendJavascript(js);
|
||||||
@ -221,6 +236,8 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
JPushPlugin.notificationAlert = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -353,27 +370,15 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
void setTags(JSONArray data, CallbackContext callbackContext) {
|
void setTags(JSONArray data, CallbackContext callbackContext) {
|
||||||
|
|
||||||
HashSet<String> tags=null;
|
|
||||||
try {
|
try {
|
||||||
String tagStr;
|
HashSet<String> tags=new HashSet<String>();
|
||||||
if(data==null){
|
for(int i=0;i<data.length();i++){
|
||||||
//tags=null;
|
tags.add(data.getString(i));
|
||||||
}else if(data.length()==0) {
|
|
||||||
tags= new HashSet<String>();
|
|
||||||
}else{
|
|
||||||
tagStr = data.getString(0);
|
|
||||||
String[] tagArray = tagStr.split(",");
|
|
||||||
for (String tag : tagArray) {
|
|
||||||
if(tags==null){
|
|
||||||
tags= new HashSet<String>();
|
|
||||||
}
|
|
||||||
tags.add(tag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//Set<String> validTags = JPushInterface.filterValidTags(tags);
|
|
||||||
JPushInterface.setTags(this.cordova.getActivity()
|
JPushInterface.setTags(this.cordova.getActivity()
|
||||||
.getApplicationContext(), tags,mTagWithAliasCallback);
|
.getApplicationContext(), tags,mTagWithAliasCallback);
|
||||||
callbackContext.success();
|
callbackContext.success();
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
callbackContext.error("Error reading tags JSON");
|
callbackContext.error("Error reading tags JSON");
|
||||||
|
@ -12,7 +12,7 @@ import android.content.Intent;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class MyReceiver extends BroadcastReceiver {
|
public class MyReceiver extends BroadcastReceiver {
|
||||||
private static String TAG = "Client Receiver";
|
private static String TAG = "JPushPlugin";
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
|
||||||
@ -42,13 +42,14 @@ public class MyReceiver extends BroadcastReceiver {
|
|||||||
JPushPlugin.transmitPush(msg, extras);
|
JPushPlugin.transmitPush(msg, extras);
|
||||||
}
|
}
|
||||||
private void handlingNotificationOpen(Context context,Intent intent){
|
private void handlingNotificationOpen(Context context,Intent intent){
|
||||||
|
Log.i(TAG, "---------------- handlingNotificationOpen");
|
||||||
|
|
||||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||||
Map<String,Object> extras = getNotificationExtras(intent);
|
Map<String,Object> extras = getNotificationExtras(intent);
|
||||||
|
|
||||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
JPushPlugin.bOpenNotificationAlert = true;
|
|
||||||
JPushPlugin.openNotificationAlert = alert;
|
JPushPlugin.openNotificationAlert = alert;
|
||||||
JPushPlugin.openNotificationExtras = extras;
|
JPushPlugin.openNotificationExtras = extras;
|
||||||
|
|
||||||
@ -57,6 +58,9 @@ public class MyReceiver extends BroadcastReceiver {
|
|||||||
context.startActivity(launch);
|
context.startActivity(launch);
|
||||||
}
|
}
|
||||||
private void handlingNotificationReceive(Context context,Intent intent){
|
private void handlingNotificationReceive(Context context,Intent intent){
|
||||||
|
|
||||||
|
Log.i(TAG, "---------------- handlingNotificationReceive");
|
||||||
|
|
||||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||||
Map<String,Object> extras = getNotificationExtras(intent);
|
Map<String,Object> extras = getNotificationExtras(intent);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user