title: Android Alarm Manager can't work
body: <p>My code has implemented the Alarm Manager Example(other question's code), however, my alarmReceiver(extends BroadcastReceiver) is not working; I don't know if my 
  MainActivity is not firing the intent or my alarmReceiver is not registered well. </p>
  
  <p>So my alarmService is not working either(since Receiver is not working). </p>
  
  <p>And I had wrote the permission,   in my manifest.xml. </p>
  
  <p>Here is the code related. Hope some one could help me with this problem. Thanks a lot.</p>
  
  <hr>
  
  <p>getBox.java</p>
  
  <hr>
  
  <pre><code> public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.getbox);
  
  
      /// 
      Intent intent = new Intent(getBox.this, AlarmReceiver.class);
      PendingIntent pendingIntent = PendingIntent.getBroadcast(getBox.this, 0, intent, 0);
      AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
      alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5 * 1000), pendingIntent);
      Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();
  </code></pre>
  
  <hr>
  
  <p>AlarmReceiver.java</p>
  
  <hr>
  
  <pre><code> public class AlarmReceiver extends BroadcastReceiver {
    @Override
      public void onReceive(Context context, Intent intent) {
          Log.d("ALARM_RECEIVER", "WORKING!!!");
          notificationStatus(context);
  
      }
      private void notificationStatus(Context context) {
          final NotificationManager mNotificationManager = (NotificationManager) 
                  context.getSystemService(Context.NOTIFICATION_SERVICE);
                  final int icon = R.drawable.icon;
          final CharSequence tickerText = context.getString(R.string.app_name);
          final long when = System.currentTimeMillis();
          final Notification notification = new Notification(icon, "ALARM_TEXT_1", when);
          final Intent notificationIntent = new Intent(context.getApplicationContext(),   getBox.class);
          final PendingIntent contentIntent = PendingIntent.getActivity(
                  context.getApplicationContext(), 0, notificationIntent, 0);
                  notification.setLatestEventInfo(context, tickerText, "ALARM_TEXT_2", contentIntent);
          mNotificationManager.notify(1, notification);
      }
  }
  </code></pre>
  
  <hr>
  
  <p>AlarmService.java</p>
  
  <hr>
  
  <pre><code> public class AlarmService extends WakefulIntentService {
    public AlarmService() {
      super("AlarmService");
    }
  
    @Override
    protected void doWakefulWork(Intent intent) {
      File log=new File(Environment.getExternalStorageDirectory(),
                        "AlarmLog.txt");
      Log.d("ALARM_SERVICE", "WORKING");
      try {
        BufferedWriter out=new BufferedWriter(
                              new FileWriter(log.getAbsolutePath(),
                                              log.exists()));
  
        out.write(new Date().toString());
        out.write("\n");
        out.close();
  
      }
      catch (IOException e) {
        Log.e("AppService", "Exception appending to log file", e);
      }
    }
  }
  </code></pre>
  
  <hr>
  
  <p>OnBootReceiver.java</p>
  
  <hr>
  
  <pre><code> public class OnBootReceiver extends BroadcastReceiver {
    private static final int PERIOD=3000;   // 3 sec
  
    @Override
    public void onReceive(Context context, Intent intent) {
      AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
      Intent i=new Intent(context, AlarmReceiver.class);
      PendingIntent pi=PendingIntent.getBroadcast(context, 0,
                                                i, 0);
  
      mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                        SystemClock.elapsedRealtime()+60000,
                        PERIOD,
                        pi);
    }
  }
  </code></pre>
  
  <hr>
  
  <p>WakefulIntentService.java</p>
  
  <hr>
  
  <pre><code> abstract public class WakefulIntentService extends IntentService {
    abstract void doWakefulWork(Intent intent);
  
    public static final String LOCK_NAME_STATIC="com.commonsware.android.syssvc.AppService.Static";
    private static PowerManager.WakeLock lockStatic=null;
  
    public static void acquireStaticLock(Context context) {
      getLock(context).acquire();
    }
  
    synchronized private static PowerManager.WakeLock getLock(Context context) {
      if (lockStatic==null) {
        PowerManager mgr=(PowerManager)context.getSystemService(Context.POWER_SERVICE);
  
        lockStatic=mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                              LOCK_NAME_STATIC);
        lockStatic.setReferenceCounted(true);
      }
  
      return(lockStatic);
    }
  
    public WakefulIntentService(String name) {
      super(name);
    }
  
    @Override
    final protected void onHandleIntent(Intent intent) {
      try {
        doWakefulWork(intent);
      }
      finally {
        getLock(this).release();
      }
    }
  }
  </code></pre>
  
  <hr>
  
  <h2>Manifest.xml</h2>
  
  <pre><code>&lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
      &lt;activity android:screenOrientation="portrait" android:name=".Mail"&gt;&lt;/activity&gt;
      &lt;activity android:screenOrientation="portrait" android:name=".getBox"&gt;
      &lt;/activity&gt;
      &lt;activity android:screenOrientation="portrait" android:name=".mainPage"&gt;&lt;/activity&gt;
      &lt;activity android:screenOrientation="portrait" android:name=".sendBox"&gt;&lt;/activity&gt;        
      &lt;activity android:screenOrientation="portrait" android:name=".main" 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;provider android:name=".DataProvider" android:authorities="com.fleax.vocalclip.dataprovider" /&gt;
  &lt;receiver android:name=".OnBootReceiver"&gt;
       &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
       &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  &lt;receiver android:name=".AlarmReceiver"&gt;&lt;/receiver&gt;
  &lt;service android:name=".AlarmService"&gt;&lt;/service&gt;
  &lt;/application
  </code></pre>