user1928775
user1928775

Reputation: 355

Alarm fires on specific days every week

I'm making an application that lets the user choose days and start an alarm on a specific time on those days.

lets take my problem as an example I want my alarm to fire every Friday at 12:30 the problem is It just never fires the alarm even though I'm in the same day here is my code

    cals = Calendar.getInstance();
    int days = Calendar.FRIDAY + (7 - cals.get(Calendar.DAY_OF_WEEK)); // how many days until Sunday
        cals.add(Calendar.DATE, days);
    cals.set(Calendar.DAY_OF_WEEK,6);                           
    cals.set(Calendar.HOUR_OF_DAY, 12);
    cals.set(Calendar.MINUTE, 30);
    cals.set(Calendar.SECOND, 0);
    cals.set(Calendar.MILLISECOND, 0);
    alarm.SetAlarm(getApplicationContext(), 10,"Start", cals.getTimeInMillis());



public void SetAlarm(Context context,int id,String sor,long time)
  {
      AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
      if(sor.equals("Start"))
      {
          Intent i = new Intent(context, MyAppReceiver.class);
          PendingIntent p = PendingIntent.getBroadcast(context, 0, i, 0);        
          am.setRepeating(AlarmManager.RTC_WAKEUP, time, DateUtils.DAY_IN_MILLIS, p);        
      }
}

Upvotes: 0

Views: 700

Answers (1)

cania
cania

Reputation: 858

Did you register your MyAppReceiver as a BroadcastReceiver in the AndroidManifest.xml?

Upvotes: 1

Related Questions