_receivers) {
+ this.intent = _intent;
+ this.receivers = _receivers;
+ }
+ }
+
+ private static class ReceiverRecord {
+ final IntentFilter filter;
+ final BroadcastReceiver receiver;
+ boolean broadcasting;
+
+ ReceiverRecord(IntentFilter _filter, BroadcastReceiver _receiver) {
+ this.filter = _filter;
+ this.receiver = _receiver;
+ }
+
+ public String toString() {
+ StringBuilder builder = new StringBuilder(128);
+ builder.append("Receiver{");
+ builder.append(this.receiver);
+ builder.append(" filter=");
+ builder.append(this.filter);
+ builder.append("}");
+ return builder.toString();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/uiuios/jpush/Logger.java b/src/com/android/uiuios/jpush/Logger.java
new file mode 100644
index 0000000..cc79a1e
--- /dev/null
+++ b/src/com/android/uiuios/jpush/Logger.java
@@ -0,0 +1,40 @@
+package com.android.uiuios.jpush;
+
+import android.util.Log;
+
+/**
+ * Created by efan on 2017/4/13.
+ */
+
+public class Logger {
+
+ //设为false关闭日志
+ private static final boolean LOG_ENABLE = true;
+
+ public static void i(String tag, String msg){
+ if (LOG_ENABLE){
+ Log.i(tag, msg);
+ }
+ }
+ public static void v(String tag, String msg){
+ if (LOG_ENABLE){
+ Log.v(tag, msg);
+ }
+ }
+ public static void d(String tag, String msg){
+ if (LOG_ENABLE){
+ Log.e(tag, msg);
+ }
+ }
+ public static void w(String tag, String msg){
+ if (LOG_ENABLE){
+ Log.w(tag, msg);
+ }
+ }
+ public static void e(String tag, String msg){
+ if (LOG_ENABLE){
+ Log.e(tag, msg);
+ }
+ }
+
+}
diff --git a/src/com/android/uiuios/jpush/MyReceiver.java b/src/com/android/uiuios/jpush/MyReceiver.java
new file mode 100644
index 0000000..b465da8
--- /dev/null
+++ b/src/com/android/uiuios/jpush/MyReceiver.java
@@ -0,0 +1,182 @@
+package com.android.uiuios.jpush;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.TextUtils;
+
+import com.android.uiuios.Launcher;
+import com.android.uiuios.MyApplication;
+import com.android.uiuios.TTUtils.APKUtils;
+import com.android.uiuios.network.BaseResponse;
+import com.android.uiuios.network.NetWorkManager;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.Iterator;
+
+import cn.jpush.android.api.JPushInterface;
+import io.reactivex.Observer;
+import io.reactivex.disposables.Disposable;
+
+/**
+ * 自定义接收器
+ *
+ * 如果不定义这个 Receiver,则:
+ * 1) 默认用户会打开主界面
+ * 2) 接收不到自定义消息
+ */
+public class MyReceiver extends BroadcastReceiver {
+ private static final String TAG = "JIGUANG-Example";
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ try {
+ Bundle bundle = intent.getExtras();
+ Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
+
+ if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
+ String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
+ Logger.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
+ //send the Registration Id to your server...
+
+ } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
+ Logger.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
+ processCustomMessage(context, bundle);
+
+ } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
+ Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知");
+ int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
+ Logger.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
+
+ } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
+ Logger.d(TAG, "[MyReceiver] 用户点击打开了通知");
+
+ //打开自定义的Activity
+ Intent i = new Intent(context, TestActivity.class);
+ i.putExtras(bundle);
+ //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ context.startActivity(i);
+
+ } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
+ boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
+ Logger.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
+ } else {
+ Logger.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
+ }
+ } catch (Exception e) {
+
+ }
+
+ }
+
+ // 打印所有的 intent extra 数据
+ private static String printBundle(Bundle bundle) {
+ StringBuilder sb = new StringBuilder();
+ for (String key : bundle.keySet()) {
+ if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
+ sb.append("\nkey:" + key + ", value:" + bundle.getInt(key));
+ } else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) {
+ sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key));
+ } else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
+ if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
+ Logger.i(TAG, "This message has no Extra data");
+ continue;
+ }
+
+ try {
+ JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
+ Iterator it = json.keys();
+
+ while (it.hasNext()) {
+ String myKey = it.next();
+ sb.append("\nkey:" + key + ", value: [" +
+ myKey + " - " + json.optString(myKey) + "]");
+ }
+ } catch (JSONException e) {
+ Logger.e(TAG, "Get message extra JSON error!");
+ }
+
+ } else {
+ sb.append("\nkey:" + key + ", value:" + bundle.get(key));
+ }
+ }
+ return sb.toString();
+ }
+
+ private static final String SEND_RUNNING_APP = "2";
+
+ //send msg to MainActivity
+ private void processCustomMessage(Context context, Bundle bundle) {
+// if (Launcher.isForeground) {
+// String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
+// String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
+// Intent msgIntent = new Intent(Launcher.MESSAGE_RECEIVED_ACTION);
+// msgIntent.putExtra(Launcher.KEY_MESSAGE, message);
+// if (!ExampleUtil.isEmpty(extras)) {
+// try {
+// JSONObject extraJson = new JSONObject(extras);
+// if (extraJson.length() > 0) {
+// msgIntent.putExtra(Launcher.KEY_EXTRAS, extras);
+// }
+// } catch (JSONException e) {
+//
+// }
+//
+// }
+// LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
+// }
+
+ String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
+ String title = bundle.getString(JPushInterface.EXTRA_TITLE);
+ String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE);
+ String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
+
+ switch (message) {
+ case SEND_RUNNING_APP:
+ sendRunningApp(context);
+ break;
+ default:
+ break;
+ }
+
+
+ }
+
+ private void sendRunningApp(Context context) {
+ String packageName = MyApplication.getInstance().getAppPackageName();
+ long time = MyApplication.getInstance().getOnClickTime();
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("app_package", packageName);
+ jsonObject.addProperty("version_name", APKUtils.getAPPVersionName(context,packageName));
+ jsonObject.addProperty("start_time", time);
+ String jsonString = jsonObject.toString();
+ NetWorkManager.getInstance().getRunningAppObservable(jsonString)
+ .subscribe(new Observer() {
+ @Override
+ public void onSubscribe(Disposable d) {
+
+ }
+
+ @Override
+ public void onNext(BaseResponse baseResponse) {
+
+ }
+
+ @Override
+ public void onError(Throwable e) {
+
+ }
+
+ @Override
+ public void onComplete() {
+
+ }
+ });
+ }
+}
diff --git a/src/com/android/uiuios/jpush/PushMessageReceiver.java b/src/com/android/uiuios/jpush/PushMessageReceiver.java
new file mode 100644
index 0000000..0d36417
--- /dev/null
+++ b/src/com/android/uiuios/jpush/PushMessageReceiver.java
@@ -0,0 +1,143 @@
+package com.android.uiuios.jpush;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.android.uiuios.Launcher;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import cn.jpush.android.api.CmdMessage;
+import cn.jpush.android.api.CustomMessage;
+import cn.jpush.android.api.JPushInterface;
+import cn.jpush.android.api.JPushMessage;
+import cn.jpush.android.api.NotificationMessage;
+import cn.jpush.android.service.JPushMessageReceiver;
+
+public class PushMessageReceiver extends JPushMessageReceiver{
+ private static final String TAG = "PushMessageReceiver";
+ @Override
+ public void onMessage(Context context, CustomMessage customMessage) {
+ Log.e(TAG,"[onMessage] "+customMessage);
+ super.onMessage(context,customMessage);
+// processCustomMessage(context,customMessage);
+ }
+
+ @Override
+ public void onNotifyMessageOpened(Context context, NotificationMessage message) {
+ Log.e(TAG,"[onNotifyMessageOpened] "+message);
+ try{
+ //打开自定义的Activity
+ Intent i = new Intent(context, TestActivity.class);
+ Bundle bundle = new Bundle();
+ bundle.putString(JPushInterface.EXTRA_NOTIFICATION_TITLE,message.notificationTitle);
+ bundle.putString(JPushInterface.EXTRA_ALERT,message.notificationContent);
+ i.putExtras(bundle);
+ //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
+ context.startActivity(i);
+ }catch (Throwable throwable){
+
+ }
+ }
+
+ @Override
+ public void onMultiActionClicked(Context context, Intent intent) {
+ Log.e(TAG, "[onMultiActionClicked] 用户点击了通知栏按钮");
+ String nActionExtra = intent.getExtras().getString(JPushInterface.EXTRA_NOTIFICATION_ACTION_EXTRA);
+
+ //开发者根据不同 Action 携带的 extra 字段来分配不同的动作。
+ if(nActionExtra==null){
+ Log.d(TAG,"ACTION_NOTIFICATION_CLICK_ACTION nActionExtra is null");
+ return;
+ }
+ if (nActionExtra.equals("my_extra1")) {
+ Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮一");
+ } else if (nActionExtra.equals("my_extra2")) {
+ Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮二");
+ } else if (nActionExtra.equals("my_extra3")) {
+ Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮三");
+ } else {
+ Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮未定义");
+ }
+ }
+
+ @Override
+ public void onNotifyMessageArrived(Context context, NotificationMessage message) {
+ Log.e(TAG,"[onNotifyMessageArrived] "+message);
+ }
+
+ @Override
+ public void onNotifyMessageDismiss(Context context, NotificationMessage message) {
+ Log.e(TAG,"[onNotifyMessageDismiss] "+message);
+ }
+
+ @Override
+ public void onRegister(Context context, String registrationId) {
+ Log.e(TAG,"[onRegister] "+registrationId);
+ }
+
+ @Override
+ public void onConnected(Context context, boolean isConnected) {
+ Log.e(TAG,"[onConnected] "+isConnected);
+ }
+
+ @Override
+ public void onCommandResult(Context context, CmdMessage cmdMessage) {
+ Log.e(TAG,"[onCommandResult] "+cmdMessage);
+ }
+
+ @Override
+ public void onTagOperatorResult(Context context,JPushMessage jPushMessage) {
+ TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage);
+ super.onTagOperatorResult(context, jPushMessage);
+ }
+ @Override
+ public void onCheckTagOperatorResult(Context context,JPushMessage jPushMessage){
+ TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context,jPushMessage);
+ super.onCheckTagOperatorResult(context, jPushMessage);
+ }
+ @Override
+ public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
+ TagAliasOperatorHelper.getInstance().onAliasOperatorResult(context,jPushMessage);
+ super.onAliasOperatorResult(context, jPushMessage);
+ }
+
+ @Override
+ public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
+ TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context,jPushMessage);
+ super.onMobileNumberOperatorResult(context, jPushMessage);
+ }
+
+ //send msg to MainActivity
+ private void processCustomMessage(Context context, CustomMessage customMessage) {
+ if (Launcher.isForeground) {
+ String message = customMessage.message;
+ String extras = customMessage.extra;
+ Intent msgIntent = new Intent(Launcher.MESSAGE_RECEIVED_ACTION);
+ msgIntent.putExtra(Launcher.KEY_MESSAGE, message);
+ if (!ExampleUtil.isEmpty(extras)) {
+ try {
+ JSONObject extraJson = new JSONObject(extras);
+ if (extraJson.length() > 0) {
+ msgIntent.putExtra(Launcher.KEY_EXTRAS, extras);
+ }
+ } catch (JSONException e) {
+
+ }
+
+ }
+ LocalBroadcastManager.getInstance(context).sendBroadcast(msgIntent);
+ }
+ }
+
+ @Override
+ public void onNotificationSettingsCheck(Context context, boolean isOn, int source) {
+ super.onNotificationSettingsCheck(context, isOn, source);
+ Log.e(TAG,"[onNotificationSettingsCheck] isOn:"+isOn+",source:"+source);
+ }
+
+}
diff --git a/src/com/android/uiuios/jpush/PushService.java b/src/com/android/uiuios/jpush/PushService.java
new file mode 100644
index 0000000..3722aea
--- /dev/null
+++ b/src/com/android/uiuios/jpush/PushService.java
@@ -0,0 +1,8 @@
+package com.android.uiuios.jpush;
+
+
+import cn.jpush.android.service.JCommonService;
+
+public class PushService extends JCommonService {
+
+}
diff --git a/src/com/android/uiuios/jpush/TagAliasOperatorHelper.java b/src/com/android/uiuios/jpush/TagAliasOperatorHelper.java
new file mode 100644
index 0000000..fd4eefc
--- /dev/null
+++ b/src/com/android/uiuios/jpush/TagAliasOperatorHelper.java
@@ -0,0 +1,338 @@
+package com.android.uiuios.jpush;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Message;
+import android.util.SparseArray;
+
+import java.util.Locale;
+import java.util.Set;
+
+import cn.jpush.android.api.JPushInterface;
+import cn.jpush.android.api.JPushMessage;
+
+/**
+ * 处理tagalias相关的逻辑
+ * */
+public class TagAliasOperatorHelper {
+ private static final String TAG = "JIGUANG-TagAliasHelper";
+ public static int sequence = 1;
+ /**增加*/
+ public static final int ACTION_ADD = 1;
+ /**覆盖*/
+ public static final int ACTION_SET = 2;
+ /**删除部分*/
+ public static final int ACTION_DELETE = 3;
+ /**删除所有*/
+ public static final int ACTION_CLEAN = 4;
+ /**查询*/
+ public static final int ACTION_GET = 5;
+
+ public static final int ACTION_CHECK = 6;
+
+ public static final int DELAY_SEND_ACTION = 1;
+
+ public static final int DELAY_SET_MOBILE_NUMBER_ACTION = 2;
+
+ private Context context;
+
+ private static TagAliasOperatorHelper mInstance;
+ private TagAliasOperatorHelper(){
+ }
+ public static TagAliasOperatorHelper getInstance(){
+ if(mInstance == null){
+ synchronized (TagAliasOperatorHelper.class){
+ if(mInstance == null){
+ mInstance = new TagAliasOperatorHelper();
+ }
+ }
+ }
+ return mInstance;
+ }
+ public void init(Context context){
+ if(context != null) {
+ this.context = context.getApplicationContext();
+ }
+ }
+ private SparseArray