0

I have write an activity that I set alarm and ıt will wake up on set time.But when time comed for alarm,it is not firing.Here is my codes;

MainActivity.java

    buttonEkle.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Yapilacaklar yapilacaklar = new Yapilacaklar(null, null, null,
                    null);

            if (!checkBoxIsAlarm.isChecked()) {
                yapilacaklar.setIsAlarm(Boolean.FALSE);
            } else {
                yapilacaklar.setIsAlarm(Boolean.TRUE);
                Intent intentsOpen = new Intent(
                        YapilacakEklemeActivity.this, AlarmReceiver.class);
                intentsOpen.setAction("com.mesutemre.alarm.ACTION");
                pendingIntent = PendingIntent.getBroadcast(
                        YapilacakEklemeActivity.this, 111, intentsOpen, 0);
                alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 10000, pendingIntent);
            }
        }
    });

Here is my AlarmReceiver;

AlarmReceiver.java

public class AlarmReceiver extends BroadcastReceiver {

private final String SOMEACTION = "com.mesutemre.alarm.ACTION";

@Override
public void onReceive(Context context, Intent intent) {
    generateNotification(context,"Hi how are you?");
    String action = intent.getAction();
    if (SOMEACTION.equals(action)) {
        //do what you want here
        generateNotification(context,"Hi how are you?");
    }
}

@SuppressWarnings("deprecation")
private void generateNotification(Context context, String message) {
      System.out.println(message+"++++++++++2");
      int icon = R.drawable.javandroid;
      long when = System.currentTimeMillis();
      NotificationManager notificationManager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
      Notification notification = new Notification(icon, message, when);
      String title = context.getString(R.string.app_name);
      String subTitle = context.getString(R.string.app_name);
      notification.defaults |= Notification.DEFAULT_SOUND;
      notification.flags |= Notification.FLAG_AUTO_CANCEL;
      notification.defaults |= Notification.DEFAULT_VIBRATE;
      notificationManager.notify(0, notification);
}

}

I have saved receiver on manifest.xml like that;

    <receiver android:name=".AlarmReceiver">
        <intent-filter>
            <action android:name="com.mesutemre.alarm.ACTION" />
        </intent-filter>
    </receiver>

Why alarm is not firing on set time?I have tried same code another app it worked fine.What can be reason?

emreturka
  • 846
  • 3
  • 18
  • 44
  • hi check this http://stackoverflow.com/questions/6520403/how-to-set-alarm-in-android and please upvote if you find it help full :) – Nitin Jan 07 '15 at 08:52
  • I have checked.But I don't understand that where is my mistake? – emreturka Jan 07 '15 at 09:20
  • just try to remove the intentsOpen.setAction("com.mesutemre.alarm.ACTION"); – Nitin Jan 07 '15 at 09:48
  • Also use NotificationCompat.Builder to avoid deprecation http://developer.android.com/guide/topics/ui/notifiers/notifications.html – Nitin Jan 07 '15 at 09:56

0 Answers0