|
using System;
|
using Android.Content;
|
using CN.Jpush.Android.Api;
|
using CN.Jpush.Android.Service;
|
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"
|
})]
|
public class JPushReceiver : JPushMessageReceiver
|
{
|
|
private static string TAG = "JPushReceiver";
|
/// <summary>
|
/// 用户点击打开了通知
|
/// 点击通知回调
|
/// </summary>
|
/// <param name="context"></param>
|
/// <param name="notificationMessage"></param>
|
public override void OnNotifyMessageOpened(Context context, NotificationMessage notificationMessage)
|
{
|
//2020-12-23 解决点击通知栏打开不了APP问题
|
//base.OnNotifyMessageOpened(context, notificationMessage);
|
|
OpenNotification(context, notificationMessage);
|
}
|
|
/// <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;
|
Utlis.WriteLine("PushMes messageType : " + pushMes.messageType);
|
}
|
|
Utlis.WriteLine("PushMes title : " + pushMes.Title);
|
Utlis.WriteLine("PushMes message : " + pushMes.Content);
|
Utlis.WriteLine("PushMes extras : " + pushMes.Extras);
|
Shared.Application.RunOnMainThread(() =>
|
{
|
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>
|
/// 注册成功回调
|
/// </summary>
|
/// <param name="p0"></param>
|
/// <param name="p1"></param>
|
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
|
/// </summary>
|
/// <param name="context"></param>
|
/// <param name="notificationMessage"></param>
|
private void OpenNotification(Context context, NotificationMessage notificationMessage)
|
{
|
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;
|
pushMes.expantContent = jpushExpandData.expantContent;
|
Utlis.WriteLine("PushMes messageType : " + pushMes.messageType);
|
}
|
|
Utlis.WriteLine("PushMes title : " + pushMes.Title);
|
Utlis.WriteLine("PushMes message : " + pushMes.Content);
|
Utlis.WriteLine("PushMes extras : " + pushMes.Extras);
|
Shared.Application.RunOnMainThread(() =>
|
{
|
Intent i = new Intent(context, typeof(BaseActivity));//Intent intent=new Intent( 起始组件对象 , 目标 Service.class);
|
i.SetFlags(ActivityFlags.NewTask);
|
context.StartActivity(i);
|
|
HDLCommon.Current.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());
|
//}
|
}
|
}
|
|
}
|