Recieve_Boot_Completed Broad Cast Reciever在xamarin android中无效

时间:2018-03-24 10:18:14

标签: android visual-studio xamarin broadcastreceiver bootcompleted

AndroidManifest.xml代码:

<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">   </uses-permission>
<application android:label="TestingApp">

<receiver android:name=".BootCompleteReciever"
          android:enabled="true"
          android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</receiver>    
</application>

BootCompleteReciever类:

[BroadcastReceiver(Enabled = true)]
[IntentFilter(new string[] { "android.intent.action.BOOT_COMPLETED" },    Priority = (int)IntentFilterPriority.LowPriority)]
public class BootCompleteReciever : BroadcastReceiver
{
    AlarmManager alarm_manager;
    TimePicker alarm_timepicker;
    Context _context;
    Calendar calndr = Calendar.GetInstance(Java.Util.TimeZone.Default);
    public override void OnReceive(Context context, Intent intent)
    {
    calndr.Set(Calendar.HourOfDay, Convert.ToDateTime(dst.Tables[0].Rows[0]              ["time1"].ToString()).Hour);
    calndr.Set(Calendar.Minute, Convert.ToDateTime(dst.Tables[0].Rows[0]                   ["time1"].ToString()).Minute);                             
    Pending Intent & Alaram Manager
    Intent myIntent;
    PendingIntent pendingIntent;
    myIntent = new Intent(_context, typeof(AlarmToastReceiver_AlaramStart));
    pendingIntent = PendingIntent.GetBroadcast(Application.Context, 0,       myIntent, PendingIntentFlags.UpdateCurrent);
     if (swt.Checked)
     {
      alarm_manager.SetRepeating(AlarmType.RtcWakeup, calndr.TimeInMillis,      AlarmManager.IntervalDay, pendingIntent);
     }
     else
      {
      alarm_manager.Set(AlarmType.RtcWakeup, calndr.TimeInMillis, pendingIntent);
       }
      }

AlarmToastReceiver_AlaramStart类:

[BroadcastReceiver(Enabled =true)]
public class AlarmToastReceiver_AlaramStart : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent)
    {
        //----------- Show Toast Massage -----------------------------
        Toast.MakeText(_context, "THIS IS MY ALARM", ToastLength.Long).Show();
    }
 }

当系统重新启动或关闭时,BootCompleteReciever类没有触发,我的Alaram在重新启动或关机后没有启动,我不知道什么问题。任何人都可以提前帮助我.Tnx。

0 个答案:

没有答案