Issues alarm manager in every 1 min Android?

前端 未结 3 1610
栀梦
栀梦 2021-01-20 17:33

I want to make a service which fire alarm manager in every 1 min interval..But my Alarm run once(first time only). I follow Lalit Answer

private class Rec         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-20 17:39

    Try this code in Your broadcast receiver's onReceive method

    AlarmManager mgr=(AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);
    mgr.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
                                  60000+System.currentTimeMillis(),
                                      getPendingIntent(ctxt));
    

    and you can get pending intent

    private static PendingIntent getPendingIntent(Context ctxt) {
        Intent i=new Intent(ctxt, AReceiver.class);
        return(PendingIntent.getBroadcast(ctxt, 0, i, 0));
    }
    

    where AReceiver class is for start service like Notification it is working fine in my app so i hope it helps you

提交回复
热议问题