wxr
2024-09-24 691dbe24f5724f153e07947c7b75bdfea5f0b6d5
HDL-ON_Android/Other/JPush/JPushReceiver.cs
@@ -1,31 +1,50 @@

using System;
using Android.App;
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;
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.hdl.onpro"
    })]
    public class JPushReceiver : JPushMessageReceiver
    //[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);
        }
        /// <summary>
        /// 用户点击打开了通知
        /// 点击通知回调
@@ -34,9 +53,10 @@
        /// <param name="notificationMessage"></param>
        public override void OnNotifyMessageOpened(Context context, NotificationMessage notificationMessage)
        {
            //2020-12-23 解决点击通知栏打开不了APP问题
            //base.OnNotifyMessageOpened(context, notificationMessage);
            OpenNotification(context, notificationMessage);
        }
@@ -62,8 +82,10 @@
                pushMes.messageType = jpushExpandData.messageType;
                pushMes.expantContent = jpushExpandData.expantContent;
                pushMes.HomeId = jpushExpandData.homeId;
                Utlis.WriteLine("PushMes messageType : " + pushMes.messageType);
                Utlis.WriteLine("收到通知回调\r\nPushMes messageType : " + pushMes.messageType);
            }
            Utlis.WriteLine("PushMes title : " + pushMes.Title);
            Utlis.WriteLine("PushMes message : " + pushMes.Content);
@@ -108,44 +130,7 @@
        public override void OnRegister(Context context, string p1)
        {
            base.OnRegister(context, p1);
            Utlis.WriteLine("JPushOnRegister: " + p1);
        }
        ///// <summary>
        ///// 处理极光信息推送
        ///// </summary>
        ///// <param name="title">标题</param>
        ///// <param name="message">信息</param>
        ///// <param name="extras">负载数据</param>
        //public void AdjustJiguangMsgPush(JPushMessageInfo JPushMessageInfo)
        //{
        //    try
        //    {
        //        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>
        /// 打开消息显示界面.010000
@@ -154,7 +139,6 @@
        /// <param name="notificationMessage"></param>
        public static void OpenNotification(Context context, NotificationMessage notificationMessage)
        {
            try
            {
                var pushMes = new JPushMessageInfo()
@@ -178,46 +162,29 @@
                Utlis.WriteLine("PushMes extras : " + pushMes.Extras);
                Utlis.WriteLine("PushMes HomeId : " + pushMes.HomeId);
                Intent i = new Intent(context, typeof(BaseActivity));//Intent intent=new Intent( 起始组件对象 , 目标 Service.class);
                i.SetFlags(ActivityFlags.NewTask);
                context.StartActivity(i);
                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.NewTask);
                    context.StartActivity(i);
                }
                //解析msg
                AdjustPushMessage(pushMes);
                //Shared.Application.RunOnMainThread(() =>
                //{
                //    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
            {
            }
            //catch (Exception ex)
            //{
            //    Utlis.WriteLine(ex.ToString());
            //}
        }
        public static void AdjustPushMessage(JPushMessageInfo pushMes)
        {
            new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                while (MainPage.BasePageView == null)