wxr
2024-08-27 bfb3d0d4879dca8c59ff287c92f5113162f3a33a
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
 
using System;
using Android.App;
using Android.Content;
using CN.Jpush.Android.Api;
using CN.Jpush.Android.Service;
using HDL_ON;
using HDL_ON.DAL.Server;
using Shared;
using Android.OS;
 
namespace HDL_ON_Android
{
 
    [BroadcastReceiver(Enabled = true, Exported = false)]
    [Android.App.IntentFilter(new string[]
    {
        "cn.jpush.android.intent.RECEIVE_MESSAGE"
    },
    Categories = new string[]
    {
        "com.rongan.smart"
    })]
    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)
        {
 
            
            //2020-12-23 解决点击通知栏打开不了APP问题
            //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
            };
 
            var jpushExpandData = GetJPushExpandData(pushMes);
            if (jpushExpandData != null && jpushExpandData.messageType != null)
            {
                pushMes.messageType = jpushExpandData.messageType;
                pushMes.expantContent = jpushExpandData.expantContent;
                pushMes.HomeId = jpushExpandData.homeId;
                Utlis.WriteLine("PushMes messageType : " + pushMes.messageType);
            }
 
            if (!string.IsNullOrEmpty(pushMes.spk))//自研可视对讲需要记录时间反呼
            {
                UserInfo.Current.pushMessageInfo = pushMes;
                UserInfo.Current.inCall = DateTime.Now;
            }
 
            Utlis.WriteLine("PushMes title : " + pushMes.Title);
            Utlis.WriteLine("PushMes message : " + pushMes.Content);
            Utlis.WriteLine("PushMes extras : " + pushMes.Extras);
            Utlis.WriteLine("PushMes HomeId : " + pushMes.HomeId);
 
            Shared.Application.RunOnMainThread(() =>
            {
                HDLCommon.Current.AdjustPushMessage(pushMes);
            });
 
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pushMes"></param>
        /// <returns></returns>
        static ExpandData GetJPushExpandData(JPushMessageInfo pushMes)
        {
            try
            {
                if (pushMes.Extras != null)
                {
                    var jpushExpandData = Newtonsoft.Json.JsonConvert.DeserializeObject<JPushExpandData>(pushMes.Extras.ToString());
                    return Newtonsoft.Json.JsonConvert.DeserializeObject<ExpandData>(jpushExpandData.expandData);
                }
                return null;
            }
            catch
            {
                return null;
            }
        }
 
 
        /// <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>
        /// 打开消息显示界面.010000
        /// </summary>
        /// <param name="context"></param>
        /// <param name="notificationMessage"></param>
        public static void OpenNotification(Context context, NotificationMessage notificationMessage)
        {
            try
            {
                var pushMes = new JPushMessageInfo()
                {
                    Title = notificationMessage.NotificationTitle,
                    Content = notificationMessage.NotificationContent,
                    Extras = notificationMessage.NotificationExtras
                };
 
                var jpushExpandData = GetJPushExpandData(pushMes);
                if (jpushExpandData != null && jpushExpandData.messageType != null)
                {
                    pushMes.messageType = jpushExpandData.messageType;
                    pushMes.expantContent = jpushExpandData.expantContent; ;
                    pushMes.HomeId = jpushExpandData.homeId;
                    Utlis.WriteLine("PushMes messageType : " + pushMes.messageType);
                }
 
                Utlis.WriteLine("PushMes title : " + pushMes.Title);
                Utlis.WriteLine("PushMes message : " + pushMes.Content);
                Utlis.WriteLine("PushMes extras : " + pushMes.Extras);
                Utlis.WriteLine("PushMes HomeId : " + pushMes.HomeId);
 
                if (Shared.Application.Activity==null)
                {
                    Intent i = new Intent(context, typeof(SplashActivity));//Intent intent=new Intent( 起始组件对象 , 目标 Service.class);
                    i.SetFlags(ActivityFlags.NewTask);
                    context.StartActivity(i);
                }
                else
                {
                    Intent i = new Intent(context, typeof(BaseActivity));//Intent intent=new Intent( 起始组件对象 , 目标 Service.class);
                    i.SetFlags(ActivityFlags.NewTask);
                    context.StartActivity(i);
                }
                //解析msg
                AdjustPushMessage(pushMes);
            }
            catch
            {
 
            }
        }
 
        public static void AdjustPushMessage(JPushMessageInfo pushMes)
        {
            new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                while (MainPage.BasePageView == null)
                {
                    System.Threading.Thread.Sleep(300);
                }
                Shared.Application.RunOnMainThread(() =>
                {
                    HDLCommon.Current.AdjustPushMessage(pushMes);
                });
            })).Start();
 
        }
    }
 
}