From 01c46e7bfe9aa8fb20b29f70c83c03a307af548a Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期二, 22 十二月 2020 16:35:16 +0800 Subject: [PATCH] 2020-12-22 1.更新。 --- HDL-ON_Android/Other/JPush/JPushReceiver.cs | 186 ++++++++++++++++++++++++++++------------------ 1 files changed, 114 insertions(+), 72 deletions(-) diff --git a/HDL-ON_Android/Other/JPush/JPushReceiver.cs b/HDL-ON_Android/Other/JPush/JPushReceiver.cs index 61b99f9..86c19ae 100644 --- a/HDL-ON_Android/Other/JPush/JPushReceiver.cs +++ b/HDL-ON_Android/Other/JPush/JPushReceiver.cs @@ -1,17 +1,9 @@ -锘縰sing System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using Android.App; +锘� using Android.Content; -using Android.OS; -using Android.Runtime; -using Android.Views; -using Android.Widget; using CN.Jpush.Android.Api; using CN.Jpush.Android.Service; using HDL_ON; +using HDL_ON.DAL.Server; using Shared; namespace HDL_ON_Android @@ -40,11 +32,7 @@ { base.OnNotifyMessageOpened(context, notificationMessage); - //App.Paras = p1.NotificationExtras; - - //Utlis.ShowTip("鏀跺埌鎺ㄩ�侊細" + p1.NotificationExtras); - Utlis.WriteLine("鏋佸厜OnNotifyMessageOpened: " + notificationMessage.NotificationContent); - Utlis.WriteLine("鏋佸厜OnNotifyMessageOpened: " + notificationMessage.NotificationExtras); + OpenNotification(context, notificationMessage); } /// <summary> @@ -55,9 +43,50 @@ public override void OnNotifyMessageArrived(Context context, NotificationMessage notificationMessage) { base.OnNotifyMessageArrived(context, notificationMessage); - Utlis.WriteLine("鏋佸厜OnNotifyMessageArrived: " + notificationMessage.NotificationContent); - Utlis.WriteLine("鏋佸厜OnNotifyMessageArrived: " + notificationMessage.NotificationExtras); + + 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; + Utlis.WriteLine("PushMes messageType : " + pushMes.messageType); + } + + Utlis.WriteLine("PushMes title : " + pushMes.Title); + Utlis.WriteLine("PushMes message : " + pushMes.Content); + Utlis.WriteLine("PushMes extras : " + pushMes.Extras); + + HDLCommon.Current.AdjustPushMessage(pushMes); } + + /// <summary> + /// + /// </summary> + /// <param name="pushMes"></param> + /// <returns></returns> + 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> /// 娉ㄥ唽鎴愬姛鍥炶皟 @@ -72,76 +101,89 @@ } ///// <summary> - ///// 鏀跺埌鑷畾涔夋秷鎭洖璋� + ///// 澶勭悊鏋佸厜淇℃伅鎺ㄩ�� ///// </summary> - ///// <param name="p0"></param> - ///// <param name="p1"></param> - //public override void OnMessage(Context p0, CustomMessage p1) + ///// <param name="title">鏍囬</param> + ///// <param name="message">淇℃伅</param> + ///// <param name="extras">璐熻浇鏁版嵁</param> + //public void AdjustJiguangMsgPush(JPushMessageInfo JPushMessageInfo) //{ - // base.OnMessage(p0, p1); + // try + // { + - // Utlis.WriteLine("鏋佸厜OnMessage: " + p1.Message.ToString()); + // 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="title">鏍囬</param> - /// <param name="message">淇℃伅</param> - /// <param name="extras">璐熻浇鏁版嵁</param> - public void AdjustJiguangMsgPush(NotificationMessage notificationMessage) - { - string title = notificationMessage.NotificationTitle; - System.Console.WriteLine(TAG, " title : " + title); - string message = notificationMessage.NotificationContent; - System.Console.WriteLine(TAG, "message : " + message); - string extras = notificationMessage.NotificationExtras; - System.Console.WriteLine(TAG, "extras : " + extras); - - - if (extras.Contains("Offline") == true) - { - - Shared.Application.RunOnMainThread(() => - { - //姝ゅ笎鍙峰凡鍦ㄥ埆澶勭櫥褰�,鎮ㄨ杩笅绾� - //ShowAlert("姝ゅ笎鍙峰凡鍦ㄥ埆澶勭櫥褰�,鎮ㄨ杩笅绾�"); - //璐﹀彿鍦ㄥ埆澶勭櫥闄嗭紝琚涪涓嬬嚎 璺宠浆鍒扮櫥褰曢〉闈� - HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices)); - - }); - return; - } - } /// <summary> /// 鎵撳紑娑堟伅鏄剧ず鐣岄潰 /// </summary> - /// <param name="context">Context.</param> - /// <param name="bundle">Bundle.</param> - private void OpenNotification(Context context, Bundle bundle) + /// <param name="context"></param> + /// <param name="notificationMessage"></param> + private void OpenNotification(Context context, NotificationMessage notificationMessage) { - - Intent i = new Intent(context, typeof(BaseActivity));//Intent intent=new Intent( 璧峰缁勪欢瀵硅薄 , 鐩爣 Service.class); - i.PutExtras(bundle); - i.SetFlags(ActivityFlags.NewTask); - context.StartActivity(i); - - String extras = bundle.GetString(JPushInterface.ExtraExtra); - //String myValue = ""; 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; + Utlis.WriteLine("PushMes messageType : " + pushMes.messageType); + } + + Utlis.WriteLine("PushMes title : " + pushMes.Title); + Utlis.WriteLine("PushMes message : " + pushMes.Content); + Utlis.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 (Exception e) + catch { - System.Console.WriteLine("JPush", "Unexpected: extras is not a valid json", e); - return; - } - + } } } -- Gitblit v1.8.0