using System; using Android.Content; using CN.Jpush.Android.Api; using CN.Jpush.Android.Service; using Com.Hdl.Hdllinphonesdk; 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" //})] //[Android.App.Service(Enabled = true)] //[Android.App.IntentFilter( // new string[] { "cn.jpush.android.intent.SERVICE_MESSAGE" }, // Categories = new string[] // { // "com.hdl.onpro" // })] [BroadcastReceiver(Enabled = true, Exported = true)] [Android.App.IntentFilter(new string[] { "cn.jpush.android.intent.SERVICE_MESSAGE" }, Categories = new string[] { "com.hdl.onpro" })] public class JPushReceiver : JPushMessageReceiver// JPushMessageService { private static string TAG = "JPushReceiver"; public override void OnMessage(Context p0, CustomMessage p1) { Console.WriteLine("收到极光推送"); base.OnMessage(p0, p1); } /// /// 用户点击打开了通知 /// 点击通知回调 /// /// /// public override void OnNotifyMessageOpened(Context context, NotificationMessage notificationMessage) { //MainPage.Log("接收到推送:点击通知回调"); OpenNotification(context, notificationMessage,true); } /// /// 收到通知回调 /// /// /// 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("收到通知回调\r\nPushMes 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); Shared.Application.RunOnMainThread(() => { HDLCommon.Current.AdjustPushMessage(pushMes); }); } /// /// /// /// /// static ExpandData GetJPushExpandData(JPushMessageInfo pushMes) { try { if (pushMes.Extras != null) { var jpushExpandData = Newtonsoft.Json.JsonConvert.DeserializeObject(pushMes.Extras.ToString()); return Newtonsoft.Json.JsonConvert.DeserializeObject(jpushExpandData.expandData); } return null; } catch { return null; } } /// /// 注册成功回调 /// /// /// public override void OnRegister(Context context, string p1) { base.OnRegister(context, p1); } /// /// 打开消息显示界面.010000 /// /// /// public static void OpenNotification(Context context, NotificationMessage notificationMessage,bool isNotification = false) { try { //MainPage.Log("接收到推送:打开消息显示界面"); var pushMes = new JPushMessageInfo() { Title = notificationMessage.NotificationTitle, Content = notificationMessage.NotificationContent, Extras = notificationMessage.NotificationExtras, isNotificationGoing = isNotification }; 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)); i.SetFlags(ActivityFlags.NewTask); context.StartActivity(i); } else { Intent i = new Intent(context, typeof(BaseActivity)); i.SetFlags(ActivityFlags.SingleTop); i.SetFlags(ActivityFlags.ClearTop); 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(); } } }