client_Hale
2018-09-04 fff1f19a381e6ad295cb3e7bd41cce48e74fbeea
Project/app/src/main/java/com/secondworld/univeralsdk/JPushReceiver.java
@@ -4,10 +4,10 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.unity3d.player.UnityPlayer;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
@@ -37,16 +37,13 @@
                String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
                Log.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
                //send the Registration Id to your server...
                Map<String, Object> _msg = new HashMap<>();
                _msg.put("code", 2004);
                _msg.put("clientID", regId);
                JSONObject _json = new JSONObject(_msg);
                UnityPlayer.UnitySendMessage("SDKUtility", "Recv_SDK_Callback", _json.toString());
                Map<String, Object> _msgStruct = new HashMap<>();
                _msgStruct.put("code", CodeA2U.PushClientID);
                _msgStruct.put("clientID", regId);
                UniversalUtil.sendMessageToUnity(_msgStruct);
            }
            else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction()))
            {
                Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(
                        JPushInterface.EXTRA_MESSAGE));
                processCustomMessage(context, bundle);
            }
            else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction()))
@@ -57,14 +54,12 @@
            }
            else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction()))
            {
//                Log.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);
                Log.d(TAG, "[MyReceiver] 用户点击打开了通知");
                //打开自定义的Activity
                Intent i = new Intent(context, MainActivity.class);
                i.putExtras(bundle);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                context.startActivity(i);
            }
            else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction()))
            {
@@ -125,15 +120,21 @@
        return sb.toString();
    }
//    public static final String KEY_TITLE = "title";
//    public static final String KEY_MESSAGE = "message";
//    public static final String KEY_EXTRAS = "extras";
    //send msg to MainActivity
    private void processCustomMessage(Context context, Bundle bundle)
    {
        Log.d(TAG, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!![MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(
                JPushInterface.EXTRA_MESSAGE));
//        if (MainActivity.isForeground) {
//            String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
//            String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
//            Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
//            msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
//            if (!ExampleUtil.isEmpty(extras)) {
//            if (!UniversalUtil.isEmpty(extras)) {
//                try {
//                    JSONObject extraJson = new JSONObject(extras);
//                    if (extraJson.length() > 0) {