как установить будильник вместе с уведомлением? - PullRequest
2 голосов
/ 05 сентября 2011

я делал над моим проектом будильника ..

мой код такой:

    String a = interval.getText().toString();

   Intent myIntent = new Intent(AndroidAlarmService.this, MyAlarmService.class);
   pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0);

            AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            calendar.add(Calendar.SECOND, 10);
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), Integer.parseInt(a)*1000, pendingIntent);

            NotificationManager mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

            int icon = R.drawable.alarm_icon;
            CharSequence tickerText = "Hello";
            long when = System.currentTimeMillis();

            Notification notification = new Notification(icon, tickerText, when);

            Context context = getApplicationContext();
            CharSequence contentTitle = "My notification";
            CharSequence contentText = "Hello World!";
            Intent notificationIntent = new Intent(AndroidAlarmService.this, AndroidAlarmService.class);
            PendingIntent contentIntent = PendingIntent.getActivity(AndroidAlarmService.this.getBaseContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

            notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

            final int HELLO_ID = 1;

            mNotificationManager.notify(HELLO_ID, notification);

   Toast.makeText(AndroidAlarmService.this, "Start Alarm", Toast.LENGTH_LONG).show();
  }});

у меня проблема, уведомление всегда выходило один раз, ононе выходить повторно.

Я хочу установить повторяемый будильник вместе с уведомлением, поэтому каждый раз, когда будильник активен, уведомление тоже будет появляться ... например, когда я устанавливаю будильник каждые 1 час,так что каждые несколько часов срабатывает будильник и также выходит уведомление.

кто-нибудь может мне помочь?спасибо, прежде чем

1 Ответ

0 голосов
/ 20 февраля 2012

передать ваше Уведомление в классе Service, т.е. внутри onStartCommand ()

...