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"; /// /// 用户点击打开了通知 /// 点击通知回调 /// /// /// 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); } /// /// 收到通知回调 /// /// /// 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); } /// /// 自定义通知 /// /// /// public override void OnMessage(Context p0, CustomMessage p1) { base.OnMessage(p0, p1); } /// /// 注册成功回调 /// /// /// 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); } /// /// /// /// /// 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; } } /// /// 接收消息通知 /// /// Context. /// Bundle. 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); } /// /// 打开消息显示界面 /// /// Context. /// Bundle. 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; } } /// /// android通知栏点击打开可视对讲的方法 /// /// 云端推过来的数据 private static void VideoMethod(string hiddenJson) { Com.Evoyohome.Sphonelibs.Global.Global.OpenCallActivity(null); } } }