admin
2022-04-29 67bdeebb4dc381a2f46f31e3027ebcc3243a8aeb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.yeshi.makemoney.video.app.push;
 
import android.content.Context;
import android.content.Intent;
import android.util.Log;
 
import com.demo.lib.common.util.common.StringUtils;
import com.yeshi.makemoney.video.app.utils.api.BasicTextHttpResponseHandler;
import com.yeshi.makemoney.video.app.utils.api.HttpApiUtil;
 
import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;
 
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.NotificationMessage;
import cn.jpush.android.service.JPushMessageReceiver;
 
public class MyJpushReceiver extends JPushMessageReceiver {
 
 
    private static final String TAG = MyJpushReceiver.class.getSimpleName();
 
    //注册成功
    @Override
    public void onRegister(Context context, String s) {
        super.onRegister(context, s);
        Log.i(TAG, "onRegister:" + s);
        if (StringUtils.isEmpty(s)) {
            return;
        }
        //获取token
        //上传token
        HttpApiUtil.uploadPushRegId(context, s, new BasicTextHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
            }
 
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                super.onSuccessPerfect(statusCode, headers, jsonObject);
            }
 
            @Override
            public void onFinish() {
                super.onFinish();
            }
        });
    }
 
    //收到消息
 
 
    @Override
    public void onMessage(Context context, CustomMessage customMessage) {
        super.onMessage(context, customMessage);
    }
 
    @Override
    public void onNotifyMessageArrived(Context context, NotificationMessage notificationMessage) {
        super.onNotifyMessageArrived(context, notificationMessage);
        Log.i(TAG, "收到通知消息:" + notificationMessage.toString());
    }
 
    @Override
    public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {
        super.onNotifyMessageOpened(context, notificationMessage);
        //intent:#Intent;component=com.yeshi.makemoney.video/.app.push.PushOpenClickActivity;end
        Log.i(TAG, "通知打开:" + notificationMessage.toString());
        String extra = notificationMessage.notificationExtras;
        if (StringUtils.isEmpty(extra)) {
            return;
        }
        try {
            JSONObject json = new JSONObject(extra);
            String type = json.optString("type");
            String params = json.opt("params") + "";
            context.startActivity(PushOpenClickActivity.createIntent(context, type, params));
        } catch (JSONException e) {
            e.printStackTrace();
        }
 
    }
 
    @Override
    public void onMultiActionClicked(Context context, Intent intent) {
        super.onMultiActionClicked(context, intent);
        Log.i(TAG, "onMultiActionClicked");
    }
}