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 java.util.Map.Entry;
|
||||
|
||||
import __PACKAGE_NAME__.R;
|
||||
import com.ljg.push.R;
|
||||
|
||||
import cn.jpush.android.api.BasicPushNotificationBuilder;
|
||||
import cn.jpush.android.api.CustomPushNotificationBuilder;
|
||||
@ -35,7 +35,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
"getRegistrationID",
|
||||
"setTags",
|
||||
"setTagsWithAlias",
|
||||
"setAlias",
|
||||
"setAlias",
|
||||
"getNotification",
|
||||
"setBasicPushNotificationBuilder",
|
||||
"setCustomPushNotificationBuilder",
|
||||
@ -48,7 +48,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
"setLatestNotificationNum",
|
||||
"setPushTime",
|
||||
"clearAllNotification",
|
||||
"clearNotificationById",
|
||||
"clearNotificationById",
|
||||
"addLocalNotification",
|
||||
"removeLocalNotification",
|
||||
"clearLocalNotifications",
|
||||
@ -58,14 +58,16 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
|
||||
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
||||
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 Map<String, Object> notificationExtras=new HashMap<String, Object>();
|
||||
public static String openNotificationAlert;
|
||||
public static Map<String, Object> openNotificationExtras=new HashMap<String, Object>();
|
||||
|
||||
|
||||
public JPushPlugin() {
|
||||
instance = this;
|
||||
}
|
||||
@ -73,28 +75,44 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
@Override
|
||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||
super.initialize(cordova, webView);
|
||||
//JPushInterface.setDebugMode(true);
|
||||
|
||||
//JPushPlugin.notificationAlert = alert;
|
||||
//JPushPlugin.notificationExtras = extras;
|
||||
|
||||
if(JPushPlugin.bOpenNotificationAlert){
|
||||
|
||||
JPushPlugin.bOpenNotificationAlert = false;
|
||||
|
||||
Log.i(TAG, "---------------- initialize"+"-"+JPushPlugin.openNotificationAlert + "-" + JPushPlugin.notificationAlert);
|
||||
|
||||
shouldCacheMsg = false;
|
||||
|
||||
if(JPushPlugin.openNotificationAlert != null){
|
||||
JPushPlugin.notificationAlert = null;
|
||||
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
|
||||
}
|
||||
if(JPushPlugin.notificationAlert!=null){
|
||||
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//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,
|
||||
Map<String, Object> extras) {
|
||||
JSONObject data = new JSONObject();
|
||||
@ -169,19 +187,18 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(JPushPlugin.shouldCacheMsg){
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i(TAG, "---------------- transmitOpen");
|
||||
|
||||
JSONObject data = openNotificationObject(alert, extras);
|
||||
String js = String
|
||||
.format("window.plugins.jPushPlugin.openNotificationInAndroidCallback('%s');",
|
||||
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 {
|
||||
instance.webView.sendJavascript(js);
|
||||
|
||||
@ -194,24 +211,22 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
JPushPlugin.openNotificationAlert = null;
|
||||
}
|
||||
static void transmitReceive(String alert, Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(JPushPlugin.shouldCacheMsg){
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject data = openNotificationObject(alert, extras);
|
||||
String js = String
|
||||
.format("window.plugins.jPushPlugin.receiveNotificationInAndroidCallback('%s');",
|
||||
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 {
|
||||
|
||||
instance.webView.sendJavascript(js);
|
||||
@ -221,6 +236,8 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
JPushPlugin.notificationAlert = null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -353,27 +370,15 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
void setTags(JSONArray data, CallbackContext callbackContext) {
|
||||
|
||||
HashSet<String> tags=null;
|
||||
try {
|
||||
String tagStr;
|
||||
if(data==null){
|
||||
//tags=null;
|
||||
}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);
|
||||
}
|
||||
HashSet<String> tags=new HashSet<String>();
|
||||
for(int i=0;i<data.length();i++){
|
||||
tags.add(data.getString(i));
|
||||
}
|
||||
//Set<String> validTags = JPushInterface.filterValidTags(tags);
|
||||
JPushInterface.setTags(this.cordova.getActivity()
|
||||
.getApplicationContext(), tags,mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("Error reading tags JSON");
|
||||
|
@ -12,7 +12,7 @@ import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class MyReceiver extends BroadcastReceiver {
|
||||
private static String TAG = "Client Receiver";
|
||||
private static String TAG = "JPushPlugin";
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
@ -42,13 +42,14 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
JPushPlugin.transmitPush(msg, extras);
|
||||
}
|
||||
private void handlingNotificationOpen(Context context,Intent intent){
|
||||
Log.i(TAG, "---------------- handlingNotificationOpen");
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
Map<String,Object> extras = getNotificationExtras(intent);
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
JPushPlugin.bOpenNotificationAlert = true;
|
||||
JPushPlugin.openNotificationAlert = alert;
|
||||
JPushPlugin.openNotificationExtras = extras;
|
||||
|
||||
@ -57,6 +58,9 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
context.startActivity(launch);
|
||||
}
|
||||
private void handlingNotificationReceive(Context context,Intent intent){
|
||||
|
||||
Log.i(TAG, "---------------- handlingNotificationReceive");
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
Map<String,Object> extras = getNotificationExtras(intent);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user