title: Android Set Event using Alarm Manager?
body: <p>I am trying to make a reminder event that would display a notification at a given time in my application for sake of this example I set the <code>Calendar</code> instance to one minute to the current time. This is my <code>appointment.java</code> code, this is where the instance of <code>Calendar</code> are initialized to current time + one minute for the sake of this example.</p>
  
  <pre><code>Calendar ctest = Calendar.getInstance();
  ctest.add(Calendar.MINUTE, 1);
  Intent myIntent = new Intent(Appointments.this, AlarmRec.class);
  pendingIntent = PendingIntent.getBroadcast(Appointments.this, 0, myIntent,0);
  AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
  alarmManager.set(AlarmManager.RTC, ctest.getTimeInMillis(), pendingIntent);
  </code></pre>
  
  <p>Then I have the following code in my <code>AlarmRec.class</code> that acts as the BroadcastReceiver.</p>
  
  <pre><code>public class AlarmRec extends BroadcastReceiver {
      public void onReceive(Context context, Intent intent) {  
          Intent service1 = new Intent(context, MyAlarmService.class);
          context.startService(service1);
      }
  }
  </code></pre>
  
  <p>Then at last in my <code>MyAlarmService.class</code> I have the following </p>
  
  <pre><code>public void onStart(Intent intent, int startId)
  {
     super.onStart(intent, startId);
  
     mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
     Intent intent1 = new Intent(this.getApplicationContext(),MainActivity.class);
  
     Notification notification = new Notification(R.drawable.ic_launcher,"This is a test message!", System.currentTimeMillis());
     intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP);
  
     PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(),0, intent1,PendingIntent.FLAG_UPDATE_CURRENT);
     notification.flags |= Notification.FLAG_AUTO_CANCEL;
     notification.setLatestEventInfo(this.getApplicationContext(), "AlarmManagerDemo", "This is a test message!", pendingNotificationIntent);
  
     mManager.notify(0, notification);
  }
  </code></pre>
  
  <p>and my <code>AndroidManifest</code> contains</p>
  
  <pre><code>  &lt;service android:name=".MyAlarmService"
               android:enabled="true" /&gt;
  
      &lt;receiver android:name=".AlarmRec"/&gt;
  </code></pre>
  
  <p>the problem I am having is nothing is being displayed no notification or anything so I'm not sure if i am doing something wrong</p>
  
  <p>Also if i have made mistakes in my post please bear with me if i made mistakes with my formatting in the question.</p>
  
  <p>EDIT</p>
  
  <p><strong>wow solved thanks for the help guys, got rid of broadcast receiver and just used the service although it was still not working at the end i realized i had a small typo in my android manifest</strong></p>
  
  <p><code>&lt;service android:name=".MyAlarmService"
                   android:enabled="true" /&gt;</code></p>
  
  <p><strong>If you see I forgot to specify my package name for the service should have been myCF.MyAlarmService</strong> </p>
  
  <p><strong>Thanks for the help everyone I really appreciate it</strong></p>