i want show notification at 8:00 am everyday

后端 未结 2 1355
無奈伤痛
無奈伤痛 2020-11-30 14:56

I\'m trying to send a notification to a user at a specific time at (8:00 am everyday) using an Alarm Manager. but my code not correct work please help me for show notificati

2条回答
  •  鱼传尺愫
    2020-11-30 15:17

    Try this set of code your service never going to stop it's works for me. "mgr.setInexactReapeating" not working in many of the lollipop and marshmallows device once it started then lose control over the service this will help you out.

    if (android.os.Build.VERSION.SDK_INT >= 23) {
            piLR = PendingIntent.getBroadcast(context, 0, intentLR,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            amLR.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                    interval, piLR);
        } else if (android.os.Build.VERSION.SDK_INT >= 19
                && android.os.Build.VERSION.SDK_INT < 23) {
            piLR = PendingIntent.getBroadcast(context, 0, intentLR,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            amLR.setInexactRepeating(AlarmManager.RTC_WAKEUP,
                    System.currentTimeMillis(), interval, piLR);
        } else {
            amLR.setRepeating(AlarmManager.RTC_WAKEUP,
                    System.currentTimeMillis(), interval, piLR);
        }
    

提交回复
热议问题