Set android alarm clock programmatically

前端 未结 3 1999
执笔经年
执笔经年 2020-12-13 07:28

I\'m trying to build a personal app that will set alarms in the DeskClock app. I can get it to set alarms for anytime in the current day, But how would I go about setting an

3条回答
  •  醉梦人生
    2020-12-13 08:16

    How about trying a pending Intent?

    Just change the Calendar value to a few days or so in advance?

    AlarmManager am = (AlarmManager)getSystemService(alarm);
    
    Intent i= new Intent("MY_INTENT");
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0);
    
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.MINUTE, 2);
    am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pi);
    

提交回复
热议问题