Android 服务通过“广播接收器”启动;随机地;

Android 服务通过“广播接收器”启动;随机地;,android,broadcastreceiver,android-service,android-notifications,Android,Broadcastreceiver,Android Service,Android Notifications,我想在每天指定的时间收到通知 为此,我实现了一个广播接收器和一个AlarmManager 我的怀疑是接收器对系统的每一次广播都有反应 因为如果我设置alarmManager,它可以正常工作一段时间,但我几乎每小时(大约)收到一次通知 还有一个奇怪的行为,如果我进入飞行模式,通知不会显示 public class MyReceiver extends BroadcastReceiver { @Override public void onReceive(Context context,

我想在每天指定的时间收到通知

为此,我实现了一个广播接收器和一个AlarmManager

我的怀疑是接收器对系统的每一次广播都有反应

因为如果我设置alarmManager,它可以正常工作一段时间,但我几乎每小时(大约)收到一次通知

还有一个奇怪的行为,如果我进入飞行模式,通知不会显示

public class MyReceiver extends BroadcastReceiver
{

  @Override
  public void onReceive(Context context, Intent intent)
  {
   Intent service1 = new Intent(context, MyAlarmService.class);
   context.startService(service1);
  }  
}
在主要活动中

    long REPEATE_TIME_MS=86400000 /*24h*/;      
/* notification handling */
    String syncConnPref = this.sharedPref.getString("notificationTime", "12:00"); 
    String[] pieces=syncConnPref.split(":");
    /* setup the start time for the alarm */
    Calendar calendar = Calendar.getInstance();
    long nowInMillisecs = calendar.getTimeInMillis();
    calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(pieces[0], 10));
    calendar.set(Calendar.MINUTE, Integer.parseInt(pieces[1], 10));
    long alarmStartTimeUnMillisecs = calendar.getTimeInMillis();
    if(alarmStartTimeUnMillisecs<=nowInMillisecs)
    {
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        alarmStartTimeUnMillisecs = calendar.getTimeInMillis();
    }

    Intent myIntent = new Intent(this.notificationContext, MyReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this.notificationContext, 0, myIntent,PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager)this.notificationContext.getSystemService(Service.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), REPEATE_TIME_MS, pendingIntent);
    Log.d(TAG, "Alarm setup with :"+ calendar.get(Calendar.HOUR_OF_DAY)+":"+ calendar.get(Calendar.MINUTE));
long REPEATE_TIME_MS=86400000/*24h*/;
/*通知处理*/
String synconpref=this.sharedPref.getString(“通知时间”,“12:00”);
String[]pieces=SynconPref.split(“:”);
/*设置警报的开始时间*/
日历=Calendar.getInstance();
long nowinmillises=calendar.getTimeInMillis();
calendar.set(calendar.HOUR\u OF_DAY,Integer.parseInt(片段[0],10));
calendar.set(calendar.MINUTE,Integer.parseInt(片段[1],10]);
long alarmStartTimeUnMillisecs=calendar.getTimeInMillis();

如果(alarmStartTimeUnMillisecsDid),您是否找到解决方案或解决方法?
    <receiver android:name="com.example.whoseturn.MyReceiver" android:enabled="true"> 
         <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>