AlarmManager在不同的API上不同时间后触发

时间:2016-08-15 09:05:21

标签: android android-alarms

这是我第一次使用AlarmReciever。这是服务的一部分:

//Service
    this.context=this;
    Intent alarm = new Intent(this.context,AlarmReceiver.class);
    boolean alarmRunning =(PendingIntent.getBroadcast(this.context,0, alarm,PendingIntent.FLAG_NO_CREATE) != null);
    if(alarmRunning == false){
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this.context,0,alarm,0);
        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(),15000,pendingIntent);
    }

我认为alarmManager.setRepeating中的15000意味着15秒。在我的带有API 19的S4 mini上是正确的。但是使用带有API 23的S7,警报会每分钟触发一次。有人知道这个问题吗?

这是我的日志:

08-15 10:54:15.949 11495-11522/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 10:55:15.619 11495-12452/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 10:56:15.619 11495-13407/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 10:57:15.629 11495-14288/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 10:58:15.629 11495-15193/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 11:00:00.039 11495-16907/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 11:00:15.599 11495-17149/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 11:01:15.619 11495-18085/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 11:02:15.659 11495-19040/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 11:03:58.049 11495-19601/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 11:06:11.419 11495-19878/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 11:11:11.349 11495-24547/com.example.entwicklung1.designtestapp D/BackgroundRunning::
08-15 11:16:11.449 11495-29123/com.example.entwicklung1.designtestapp D/BackgroundRunning::

正如我所见,它现在每隔几分钟就会发射一次。

0 个答案:

没有答案