using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using CN.Jpush.Android.Api;
using CN.Jpush.Android.Service;
using HDL_ON;
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);
//App.Paras = p1.NotificationExtras;
//Utlis.ShowTip("收到推送:" + p1.NotificationExtras);
Utlis.WriteLine("极光OnNotifyMessageOpened: " + notificationMessage.NotificationContent);
Utlis.WriteLine("极光OnNotifyMessageOpened: " + notificationMessage.NotificationExtras);
}
///
/// 收到通知回调
///
///
///
public override void OnNotifyMessageArrived(Context context, NotificationMessage notificationMessage)
{
base.OnNotifyMessageArrived(context, notificationMessage);
Utlis.WriteLine("极光OnNotifyMessageArrived: " + notificationMessage.NotificationContent);
Utlis.WriteLine("极光OnNotifyMessageArrived: " + notificationMessage.NotificationExtras);
}
///
/// 注册成功回调
///
///
///
public override void OnRegister(Context context, string p1)
{
base.OnRegister(context, p1);
Utlis.WriteLine("JPushOnRegister: " + p1);
}
/////
///// 收到自定义消息回调
/////
/////
/////
//public override void OnMessage(Context p0, CustomMessage p1)
//{
// base.OnMessage(p0, p1);
// Utlis.WriteLine("极光OnMessage: " + p1.Message.ToString());
//}
///
/// 处理极光信息推送
///
/// 标题
/// 信息
/// 负载数据
public void AdjustJiguangMsgPush(NotificationMessage notificationMessage)
{
string title = notificationMessage.NotificationTitle;
System.Console.WriteLine(TAG, " title : " + title);
string message = notificationMessage.NotificationContent;
System.Console.WriteLine(TAG, "message : " + message);
string extras = notificationMessage.NotificationExtras;
System.Console.WriteLine(TAG, "extras : " + extras);
if (extras.Contains("Offline") == true)
{
Shared.Application.RunOnMainThread(() =>
{
//此帐号已在别处登录,您被迫下线
//ShowAlert("此帐号已在别处登录,您被迫下线");
//账号在别处登陆,被踢下线 跳转到登录页面
HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
});
return;
}
}
///
/// 打开消息显示界面
///
/// Context.
/// Bundle.
private void OpenNotification(Context context, Bundle bundle)
{
Intent i = new Intent(context, typeof(BaseActivity));//Intent intent=new Intent( 起始组件对象 , 目标 Service.class);
i.PutExtras(bundle);
i.SetFlags(ActivityFlags.NewTask);
context.StartActivity(i);
String extras = bundle.GetString(JPushInterface.ExtraExtra);
//String myValue = "";
try
{
}
catch (Exception e)
{
System.Console.WriteLine("JPush", "Unexpected: extras is not a valid json", e);
return;
}
}
}
}