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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
 
using Android.Content;
using CN.Jpush.Android.Api;
using CN.Jpush.Android.Service;
using HDL_ON;
using HDL_ON.DAL.Server;
using Shared;
 
namespace HDL_ON_Android
{
    
    [BroadcastReceiver(Enabled = true, Exported = false)]
    [Android.App.IntentFilter(new string[]
    {
        "cn.jpush.android.intent.RECEIVE_MESSAGE"
    },
    Categories=new string[] 
    {
        "com.hdl.onpro"
    })]
    public class JPushReceiver : JPushMessageReceiver
    {
 
        private static string TAG = "JPushReceiver";
        /// <summary>
        /// 用户点击打开了通知
        /// 点击通知回调
        /// </summary>
        /// <param name="context"></param>
        /// <param name="notificationMessage"></param>
        public override void OnNotifyMessageOpened(Context context, NotificationMessage notificationMessage)
        {
            base.OnNotifyMessageOpened(context, notificationMessage);
 
            OpenNotification(context, notificationMessage);
        }
 
        /// <summary>
        /// 收到通知回调
        /// </summary>
        /// <param name="p0"></param>
        /// <param name="p1"></param>
        public override void OnNotifyMessageArrived(Context context, NotificationMessage notificationMessage)
        {
            base.OnNotifyMessageArrived(context, notificationMessage);
 
            var pushMes = new JPushMessageInfo()
            {
                Title = notificationMessage.NotificationTitle,
                Content = notificationMessage.NotificationContent,
                Extras = notificationMessage.NotificationExtras
            };
            System.Console.WriteLine("PushMes title : " + pushMes.Title);
            System.Console.WriteLine("PushMes message : " + pushMes.Content);
            System.Console.WriteLine("PushMes extras : " + pushMes.Extras);
 
            HDLCommon.Current.AdjustPushMessage(pushMes);
        }
 
        /// <summary>
        /// 注册成功回调
        /// </summary>
        /// <param name="p0"></param>
        /// <param name="p1"></param>
        public override void OnRegister(Context context, string p1)
        {
            base.OnRegister(context, p1);
 
            Utlis.WriteLine("JPushOnRegister: " + p1);
        }
 
        ///// <summary>
        ///// 处理极光信息推送
        ///// </summary>
        ///// <param name="title">标题</param>
        ///// <param name="message">信息</param>
        ///// <param name="extras">负载数据</param>
        //public void AdjustJiguangMsgPush(JPushMessageInfo JPushMessageInfo)
        //{
        //    try
        //    {
               
 
        //        if (JPushMessageInfo.Extras.Contains("Offline") == true)
        //        {
        //            Shared.Application.RunOnMainThread(() =>
        //            {
        //                //账号在别处登陆,被踢下线 跳转到登录页面
        //                new Alert(Language.StringByID(StringId.Tip), Language.StringByID(StringId.LoggedOnOtherDevices), Language.StringByID(StringId.Close)).Show();
        //                //2020-12-04 待增加退出登录操作
        //            });
        //            return;
        //        }
        //        else
        //        {
        //            Shared.Application.RunOnMainThread(() =>
        //            {
        //                new Alert(JPushMessageInfo.Title, JPushMessageInfo.Content, Language.StringByID(StringId.Close)).Show();
        //            });
        //            return;
 
        //        }
        //    }
        //    catch
        //    {
 
        //    }
        //}
 
        /// <summary>
        /// 打开消息显示界面
        /// </summary>
        /// <param name="context"></param>
        /// <param name="notificationMessage"></param>
        private void OpenNotification(Context context, NotificationMessage notificationMessage)
        {
            try
            {
                var pushMes = new JPushMessageInfo()
                {
                    Title = notificationMessage.NotificationTitle,
                    Content = notificationMessage.NotificationContent,
                    Extras = notificationMessage.NotificationExtras
                };
                System.Console.WriteLine("PushMes title : " + pushMes.Title);
                System.Console.WriteLine("PushMes message : " + pushMes.Content);
                System.Console.WriteLine("PushMes extras : " + pushMes.Extras);
 
                if (Shared.Application.Activity == null)
                {
                    var tempIntent = new Intent(context, typeof(Shared.BaseActivity));//Intent intent=new Intent( 起始组件对象 , 目标 Service.class);
                    tempIntent.SetFlags(ActivityFlags.BroughtToFront);
                    context.StartActivity(tempIntent);
 
                    HDLCommon.Current.AdjustPushMessage(pushMes);
                }
                else
                {
                    (Shared.Application.Activity as BaseActivity).MoveToFront();
 
                    HDLCommon.Current.AdjustPushMessage(pushMes);
                }
            }
            catch
            {
 
            }
        }
    }
    
}