как установить будильник вместе с уведомлением?

я делал на моем проекте сигнализации ..

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

    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 час, поэтому каждый час будильник будет срабатывать, и тоже придет уведомление..

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


person Handy    schedule 05.09.2011    source источник
comment
почему вы помещаете уведомление в тот же класс, где вы устанавливаете будильник. Уведомление должно находиться в классе MyAlarmService.   -  person Farhana Haque    schedule 05.09.2011
comment
о, понятно, всем большое спасибо :D   -  person Handy    schedule 05.09.2011


Ответы (1)


передайте свое уведомление в классе обслуживания, т.е. внутри onStartCommand()

person DineshKumar    schedule 20.02.2012