Alarm receive don't work

前端 未结 2 2001
闹比i
闹比i 2021-01-26 06:08

I\'m making an alarm receiver, but the alarm is not triggered.

This is my code :

Start alarm in MainActivity :

private void setupAlarm(){
    In         


        
2条回答
  •  庸人自扰
    2021-01-26 06:28

    Your Intent is used to explicitly start the AlarmReceiver class which is a BroadcastReceiver. Hence, you need to use getBroadcast(), not getService(), to create the PendingIntent object.

    Replace

    PendingIntent pIntent = PendingIntent.getService(this, 0, intent, 0);       
    

    with

    PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, intent, 0);  
    

    Try this. This will work.

提交回复
热议问题