Alarm receive don't work

前端 未结 2 1961
闹比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:26

    Try To Use THis. It will Work for you

    private void setupAlarm(){
    Intent intent = new Intent(this, com.logdata.AlarmReceiver.class);
    PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, intent, 0);       
    AlarmManager manager = (AlarmManager)  getSystemService(Context.ALARM_SERVICE);
     manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,SystemClock.elapsedRealtime() + 1, 1000, pIntent);
    
    Log.e("setupAlarm", "Setup alarm complete");
    

    }

提交回复
热议问题