how do i set an alarm manager to fire every on specific day of week and time in android?

后端 未结 2 1697
-上瘾入骨i
-上瘾入骨i 2020-12-04 23:02

for example i want to have an alarm that will fire every sunday at noon.... how would i do this?

2条回答
  •  半阙折子戏
    2020-12-05 00:01

    finally this right solution if set as (sun,tus ,fri) you must create three alarm for these three day the following code set alarm every sunday and send dayOfWeek=1;

     public void setAlarm_sun(int dayOfWeek) {
         cal1.set(Calendar.DAY_OF_WEEK, dayOfWeek);
         Toast.makeText(getApplicationContext(), "sun "+cal1.get(Calendar.DAY_OF_WEEK), 222).show();
    
         Toast.makeText(getApplicationContext(), "Finsh", 222).show();
    
            Intent intent = new Intent(this, SecActivity.class);
            PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0,
                    intent, 0);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 12345,
                    intent, PendingIntent.FLAG_UPDATE_CURRENT);
    
             Long alarmTime = cal1.getTimeInMillis();
             AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);
    
           // am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,7* 24 * 60 * 60 * 1000 , pendingIntent);
            am.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime,7* 24 * 60 * 60 * 1000 , pendingIntent);
    
    } 
    

提交回复
热议问题