wxr
2020-12-01 a2927467ebfa938a420f392deb6882b35570fd33
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using System;
using Android.App;
using Android.Content;
using Android.OS;
using CN.Jpush.Android.Api;
using CN.Jpush.Android.Service;
using HDL_ON;
using Shared;
 
namespace HDL_ON_Android
{
    [BroadcastReceiver(Name = "com.hdl.onpro.JpushNotificationReceiver", Exported = false, Enabled = true)]
    [IntentFilter(new string[] { "cn.jpush.android.intent.REGISTRATION",
               "cn.jpush.android.intent.MESSAGE_RECEIVED",
                "cn.jpush.android.intent.NOTIFICATION_RECEIVED",
                "cn.jpush.android.intent.NOTIFICATION_OPENED",
                "cn.jpush.android.intent.CONNECTION"  }, Categories = new string[] { "com.hdl.onpro" })]
    public class JpushNotificationReceiver : BroadcastReceiver
    {
        private static string TAG = "JpushNotificationReceiver";
        private NotificationManager nm;
        static string ACTION = "android.intent.action.BOOT_COMPLETED";
        public override void OnReceive(Context context, Intent intent)
        {
            if (nm == null)
            {
                nm = (NotificationManager)context.GetSystemService(Context.NotificationService);
            }
            //base.OnReceive (context, intent);
            try
            {
                Bundle bundle = intent.Extras;
                if (intent.Action == ACTION)
                {
                    //开机自动服务自动启动,PushService是要启动的服务
                    Intent service = new Intent(context, typeof(PushService));
                    context.StartService(service);
                }
 
                //接收Registration Id
                if (JPushInterface.ActionRegistrationId == intent.Action)
                {
                    string regId = bundle.GetString(JPushInterface.ExtraRegistrationId);
                    if (!string.IsNullOrEmpty(regId))
                    {
                        OnAppConfig.Instance.PushDeviceToken = regId;
                        //OnAppConfig.Instance.PhoneName = userPhoneName;
                        OnAppConfig.Instance.SaveUserConfig();
                    }
                }
                //用户点击打开了通知
                else if (JPushInterface.ActionNotificationOpened == intent.Action)
                {
                    OpenNotification(context, bundle);
                }
                //接受到推送下来的通知
                else if (JPushInterface.ActionNotificationReceived == intent.Action)
                {
                    //int notifactionId = bundle.GetInt(JPushInterface.ExtraNotificationId);
                    ReceivingNotification(context, bundle);
                    //Shared.Common.CommonPage.Instance.SingOut();
                }
                //接收到推送下来的自定义消息
                else if (JPushInterface.ActionMessageReceived == intent.Action)
                {
                    bundle.GetString(JPushInterface.ExtraMessage);
                }
                else
                {
                }
            }
            catch (System.Exception e)
            {
 
                System.Console.WriteLine("极光推送出错:" + e.Message);
            }
        }
        /// <summary>
        /// 接收消息通知
        /// </summary>
        /// <param name="context">Context.</param>
        /// <param name="bundle">Bundle.</param>
        private void ReceivingNotification(Context context, Bundle bundle)
        {
            String title = bundle.GetString(JPushInterface.ExtraNotificationTitle);
            System.Console.WriteLine(TAG, " title : " + title);
            String message = bundle.GetString(JPushInterface.ExtraAlert);
            System.Console.WriteLine(TAG, "message : " + message);
            String extras = bundle.GetString(JPushInterface.ExtraExtra);
            System.Console.WriteLine(TAG, "extras : " + extras);
 
            //处理极光消息推送的逻辑函数
            AdjustJiguangMsgPush(title, message, extras);
        }
 
        /// <summary>
        /// 处理极光信息推送
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="message">信息</param>
        /// <param name="extras">负载数据</param>
        public void AdjustJiguangMsgPush(string title, string message, string extras)
        {
            if (extras.Contains("Offline") == true)
            {
               
                Shared.Application.RunOnMainThread(() =>
                {
                    //此帐号已在别处登录,您被迫下线
                    //ShowAlert("此帐号已在别处登录,您被迫下线");
                    //账号在别处登陆,被踢下线 跳转到登录页面
                    HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
 
                });
                return;
            }
        }
 
        /// <summary>
        /// 打开消息显示界面
        /// </summary>
        /// <param name="context">Context.</param>
        /// <param name="bundle">Bundle.</param>
        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
            {
                VideoMethod(extras);
                //JSONObject extrasJson = new JSONObject(extras);
                //myValue = extrasJson.OptString("myKey");
 
            }
            catch (Exception e)
            {
                System.Console.WriteLine(TAG, "Unexpected: extras is not a valid json", e);
                return;
            }
 
            //if (TYPE_THIS.equals(myValue))
            //{
            //Intent mIntent = new Intent(context, ThisActivity.class);
            //mIntent.putExtras(bundle);
            //mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //context.startActivity(mIntent);
            //}
            //else if (TYPE_ANOTHER.equals(myValue))
            //{
            //Intent mIntent = new Intent(context, AnotherActivity.class);
            //mIntent.putExtras(bundle);
            //mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //context.startActivity(mIntent);
            //}
        }
 
        /// <summary>
        /// android通知栏点击处理方法
        /// </summary>
        /// <param name="hiddenJson">云端推过来的数据</param>
        private void VideoMethod(string hiddenJson)
        {
            Utlis.WriteLine("JPUSH:" + hiddenJson);
            var hiddanJson = Newtonsoft.Json.Linq.JObject.Parse(hiddenJson);
            if (hiddanJson == null)
            {
                return;
            }
            var json = Newtonsoft.Json.Linq.JObject.Parse(hiddanJson["HiddanJson"].ToString());
            if (json == null)
            {
                return;
            }
 
            
 
        }
    }
 
}