Intent intent = new Intent(context, MyBroadcastReceiver.class); PendingIntent pi= PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if(Build.VERSION.SDK_INT >= 23){ alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + INTERVAL, pi); } else if(Build.VERSION.SDK_INT >= 19){ alarmManager.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + INTERVAL, pi); } else { alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + INTERVAL, pi); } 可以在receiver里面再写一次,达到设置定时重复任务的效果。
AlarmManager简单用法记录
最新推荐文章于 2024-01-06 08:45:00 发布