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