如何在Android 6.0中重复警报 [英] How to repeat alarm in android 6.0

查看:69
本文介绍了如何在Android 6.0中重复警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 setExactAndAllowWhileIdle()设置警报。但是它只能工作一次。如何设置间隔为1天的重复警报?在API级别23之前的
setInexactRepeating 方法可以正常工作。

I am using the setExactAndAllowWhileIdle() to set the alarm. But it works for only one time. How will I set the repeating alarm with interval 1 day? Before the API Level 23 setInexactRepeating method working fine.

推荐答案

当您广播接收器事件正在执行时,请重新充电。

Recharge your alarm when you broadcast receiver event is executing.

我的意思是,

public class CustomBroadcast extends WakefulBroadcastReceiver {
    public static final String somekey = "somekey.somekey.somekey";
    @Override
    public void onReceive(Context ctx, Intent intent) {
        // TODO Auto-generated method stub
        ComponentName comp = new ComponentName(ctx.getPackageName(),
        YourSevice.class.getName());
        YourCustomClass.yourrechargefunction();
        startWakefulService(ctx, intent.setComponent(comp));
    }
}

public class YourCustomClass {
    private final static int somekey_int = anynumber;
    public static void yourrechargefunction() {
        Intent intent = new Intent(CustomBroadcast.somekey):
        PendingIntent pi = wPendingIntent.getBroadcast(ctx,somekey_int, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, nexttime, pi);
    }
}

这篇关于如何在Android 6.0中重复警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆