HDL Home App 第二版本 旧平台金堂用 正在使用
hxb
2022-08-29 9a4629512ccf8359efd88671c9317c3cc7faf0c8
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
using System;
using Android.App;
using Android.Content;
using Android.OS;
using CN.Jpush.Android.Api;
using CN.Jpush.Android.Service;
using Shared;
using static Shared.Common.SendDataToServer;
 
namespace GateWay.Droid.JPush
{
    [BroadcastReceiver(Enabled = true, Exported = false)]
    [IntentFilter(new string[]
    {
        "cn.jpush.android.intent.RECEIVE_MESSAGE"
    },
    Categories = new string[]
    {
        "com.evoyo.home"
    })]
    public class JpushNotificationReceiver : JPushMessageReceiver
    {
        private static string TAG = "JpushNotificationReceiver";
        private NotificationManager nm;
        static string ACTION = "android.intent.action.BOOT_COMPLETED";
 
        /// <summary>
        /// 用户点击打开了通知
        /// 点击通知回调
        /// </summary>
        /// <param name="context"></param>
        /// <param name="notificationMessage"></param>
        public override void OnNotifyMessageOpened(Context context, NotificationMessage notificationMessage)
        {
            //2020-12-23 解决点击通知栏打开不了APP问题
            var pushMes = new JPushMessageInfo()
            {
                Title = notificationMessage.NotificationTitle,
                Content = notificationMessage.NotificationContent,
                Extras = notificationMessage.NotificationExtras
            };
            OpenNotification(context, pushMes.Extras);
        }
 
        /// <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;
            }
 
            ReceivingNotification(context, pushMes.Title, pushMes.Content, pushMes.Extras);
        }
 
        /// <summary>
        /// 自定义通知
        /// </summary>
        /// <param name="p0"></param>
        /// <param name="p1"></param>
        public override void OnMessage(Context p0, CustomMessage p1)
        {
            base.OnMessage(p0, p1);
        }
 
        /// <summary>
        /// 注册成功回调
        /// </summary>
        /// <param name="p0"></param>
        /// <param name="p1"></param>
        public override void OnRegister(Context context, string regId)
        {
            base.OnRegister(context, regId);
            Shared.Common.Config.Instance.RegistrationID = regId;
            Shared.Common.Config.Instance.Save();
            Shared.Phone.UserCenter.HdlLogLogic.Current.WriteOtherText(Shared.Phone.UserCenter.DirNameResourse.JiguangFile, "receive2:" + regId, false, true);
        }
 
        /// <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="context">Context.</param>
        /// <param name="bundle">Bundle.</param>
        private static void ReceivingNotification(Context context, string title, string message, string extras)
        {
            System.Console.WriteLine(TAG, " title : " + title);
            System.Console.WriteLine(TAG, "message : " + message);
            System.Console.WriteLine(TAG, "extras : " + extras);
 
            //处理极光消息推送的逻辑函数
            Shared.Phone.UserCenter.HdlJiguangMsgPushLogic.Current.AdjustJiguangMsgPush(title, message, extras);
        }
 
        /// <summary>
        /// 打开消息显示界面
        /// </summary>
        /// <param name="context">Context.</param>
        /// <param name="bundle">Bundle.</param>
        public static void OpenNotification(Context context, string extras)
        {
            Intent i = new Intent(context, typeof(BaseActivity));//Intent intent=new Intent( 起始组件对象 , 目标 Service.class);
            i.SetFlags(ActivityFlags.NewTask);
            context.StartActivity(i);
            try
            {
                VideoMethod(extras);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(TAG, "Unexpected: extras is not a valid json", e);
                return;
            }
        }
 
        /// <summary>
        /// android通知栏点击打开可视对讲的方法
        /// </summary>
        /// <param name="hiddenJson">云端推过来的数据</param>
        private static void VideoMethod(string hiddenJson)
        {
            Com.Evoyohome.Sphonelibs.Global.Global.OpenCallActivity(null);
        }
 
       
    }
}