admin
2022-05-11 f19071bd5e0007fc823f99cdfa0196391827da1e
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
package com.demo.app.push;
 
import android.content.Context;
import android.content.Intent;
import android.util.Log;
 
import com.demo.lib.common.util.common.StringUtils;
 
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
        //TODO 上传token
    }
 
    //收到消息
 
 
    @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");
    }
}