0

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);        
      }
}
user1928775
  • 355
  • 1
  • 5
  • 15

1 Answers1

1

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

cania
  • 857
  • 10
  • 16
  • Yes, What I've just found out that all week days set by the same variable which is "cals" ? is there any way I can avoid that ? – user1928775 Feb 14 '14 at 23:04
  • 1
    there's nothing wrong with using cals here to set everything... i just tried the code you posted, and it worked no problem (provided i had the broadcastreceiver set in the AndroidManifest.xml) and i removed the line 'cals.add(Calendar.DATE, days);' which of course points to next week – cania Feb 14 '14 at 23:07