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";
///
/// 用户点击打开了通知
/// 点击通知回调
///
///
///
public override void OnNotifyMessageOpened(Context context, NotificationMessage notificationMessage)
{
base.OnNotifyMessageOpened(context, notificationMessage);
OpenNotification(context, notificationMessage);
}
///
/// 收到通知回调
///
///
///
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
};
System.Console.WriteLine("PushMes title : " + pushMes.Title);
System.Console.WriteLine("PushMes message : " + pushMes.Content);
System.Console.WriteLine("PushMes extras : " + pushMes.Extras);
HDLCommon.Current.AdjustPushMessage(pushMes);
}
///
/// 注册成功回调
///
///
///
public override void OnRegister(Context context, string p1)
{
base.OnRegister(context, p1);
Utlis.WriteLine("JPushOnRegister: " + p1);
}
/////
///// 处理极光信息推送
/////
///// 标题
///// 信息
///// 负载数据
//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
// {
// }
//}
///
/// 打开消息显示界面
///
///
///
private void OpenNotification(Context context, NotificationMessage notificationMessage)
{
try
{
var pushMes = new JPushMessageInfo()
{
Title = notificationMessage.NotificationTitle,
Content = notificationMessage.NotificationContent,
Extras = notificationMessage.NotificationExtras
};
System.Console.WriteLine("PushMes title : " + pushMes.Title);
System.Console.WriteLine("PushMes message : " + pushMes.Content);
System.Console.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
{
}
}
}
}