实际上我正在尝试制作我的大学日常应用程序..它使用NotificationManager向用户通知当前周期(我总共有九个周期,有些处于不同的时间间隔)...它一切正常,但是当设备进入休眠状态时出现问题,它不会在 sleep 模式下推送任何通知...我正在使用服务来推送通知,但我猜服务也会在 sleep 模式下进入休眠状态...我的服务在 sleep 期间永远不会自动终止...但它不会发出任何通知...请帮助我
最佳答案
我使用广播接收器执行此操作,我设置每 60 秒重复一次广播
像这样:
Intent notificationIntent = new Intent(context,thebroadcastclass.class);
notificationIntent.addCategory("android.intent.category.HIGH");
broadcast = PendingIntent.getBroadcast(context.getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),60000, broadcast);
它工作正常,但间隔必须至少 60 秒 (这会耗尽电池太多)
这是广播接收器:
public class thebroadcastclass extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
toastmaker.update(context, intent);
}}
我希望你能使用这个(:
关于java - 当设备处于 sleep 模式时,如何在 Android 中的某个特定时间推送本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39015678/