JLChen
2020-09-08 45d7c5536bd9b4516feb1401753e61717d7dd888
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
using System;
using Android.Content;
using Android.OS;
using CN.Jpush.Android.Api;
using CN.Jpush.Android.Service;
 
namespace com.hdl.on
{
    //<receiver android:name="com.hdl.on.MyReceiver" android:exported="false" android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
    //    <intent-filter>
    //        <action android:name="cn.jpush.android.intent.REGISTRATION" />
    //        <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
    //        <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
    //        <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
    //        <action android:name="cn.jpush.android.intent.CONNECTION" />
    //        <category android:name="com.hdl.on" />
    //        <action android:name="android.intent.action.BOOT_COMPLETED"></action>
    //        <category android:name="android.intent.category.LAUNCHER" />
    //        <action android:name="android.intent.action.USER_PRESENT" />
    //        <action android:name="android.media.RINGER_MODE_CHANGED" />
    //    </intent-filter>
    //</receiver>
    /*
  *创建一个广播
 * 自定义接收器
 * 如果不定义这个 Receiver,则:
 *  1) 默认用户会打开主界面 
 *  2) 接收不到自定义消息
 */
    //[BroadcastReceiver]
    //[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"})]
    public class MyReceiver : BroadcastReceiver
    {
        static string ACTION = "android.intent.action.BOOT_COMPLETED";
 
        public override void OnReceive (Context context, Intent intent)
        {
            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);
            }
            //用户点击打开了通知
            else if (JPushInterface.ActionNotificationOpened == intent.Action) {
                Application.IsShowTip = false;
                Intent i = new Intent (context, typeof (Shared.BaseActivity));//Intent intent=new Intent( 起始组件对象 , 目标 Service.class);
                i.PutExtras (bundle);
                i.SetFlags (ActivityFlags.NewTask);
                context.StartActivity (i);
            } else {
            }
        }
    }
}