title: Setting a repeating Notification with an AlarmManager - Android
body: <p>I am using a TimePicker to get a specific time from the user. I am then using this time to set a repeating alarm at this time every day. When the alarm goes off i want a Notification to go be sent to user. My code seems to be right and i am not getting any errors in android studio, but when i run this app and set it at a specific time...IT NEVER GOES OFF. please help. Also i haven't been able to find anything that shows me how to get the AM or PM user selection with the TimePicker. My code is below. Thanks in advance.</p>
  
  <p>Here is MyActivity ( the one that opens upon launch ) </p>
  
  <pre><code>public class MyActivity extends Activity {
  
  TimePicker mTimePicker;
  Button setAlarm;
  private int hour;
  private int minute;
  PendingIntent mPendingIntent;
  int AM_PM;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_my);
  
  
  
      setAlarm = (Button) findViewById(R.id.setUpAlarm);
  
  
      mTimePicker = (TimePicker) findViewById(R.id.timePicker);
  
      setAlarm.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
  
              setAlarm();
  
  
  
          }
      });
  
  
  
  }
  
  private void setAlarm() {
      hour = mTimePicker.getCurrentHour();
      minute = mTimePicker.getCurrentMinute();
  
      Intent intent = new Intent(this, NotifyService.class);
      AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
      mPendingIntent = PendingIntent.getService(this, 0, intent, 0);
  
      Calendar calendar = Calendar.getInstance();
      calendar.set(Calendar.SECOND , 0 );
      calendar.set(Calendar.MINUTE , 0 + minute);
      calendar.set(Calendar.HOUR , 0 + hour);
      calendar.set(Calendar.AM_PM , Calendar.PM);
  
  
      Toast.makeText(this, calendar.get(Calendar.MINUTE) + "    " + calendar.get(Calendar.HOUR), Toast.LENGTH_SHORT).show();
  
      //  * 60 * 60 * 24
  
      alarmManager.setRepeating(AlarmManager.RTC_WAKEUP , calendar.getTimeInMillis() , 1000 * 60 * 60 * 24 , mPendingIntent);
  
      // Toast.makeText(MyActivity.this , "Alarm Set" , Toast.LENGTH_SHORT).show();
  }
  </code></pre>
  
  <p>Here is my notification class</p>
  
  <pre><code>public class NotifyService extends Service {
  @Override
  public IBinder onBind(Intent intent) {
      return null;
  }
  
  @Override
  public void onCreate() {
  
      Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  
      NotificationManager mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
      Intent intent = new Intent(this.getApplicationContext() , MyActivity.class);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , intent ,0 );
  
      Notification mNotify = new Notification.Builder(this)
              .setContentTitle("Come Back!")
              .setContentText("Have you seen todays tip?")
              .setSmallIcon(R.drawable.ic_launcher)
              .setContentIntent(pendingIntent)
              .setSound(sound)
              .build();
  
      mNM.notify( 1 , mNotify);
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My manifest </p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.androidy.notificationapp" &gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".MyActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>