AlarmManager with Notification Android

前端 未结 4 1158
故里飘歌
故里飘歌 2021-01-07 02:37

I\'m trying to give the user a notification each day on a certain time so I use an AlarmManager with a notification. I have this:

public void check_products(         


        
4条回答
  •  余生分开走
    2021-01-07 03:09

    Call receiver in your manifest file.

    Like this

    
    
         
            
                   
            
         
    
    

    Or

    Try this whole example

    MainActivity.java

        private PendingIntent pendingIntent;
    
        Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
                pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent , 0);
                AlarmManager littlefluppy = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
                littlefluppy.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 2000, pendingIntent);
    

    AlarmReceiver.java

    public class AlarmReceiver extends BroadcastReceiver {
        public AlarmReceiver() {
        }
    
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO: This method is called when the BroadcastReceiver is receiving
            // an Intent broadcast.
    
        Log.e("alram set.....","");
        }
    }
    

提交回复
热议问题