2012-04-10 1 views
0

Я использую класс таймера обратного отсчета и в состоянии onfinish() этого класса. Я создаю уведомление. Вот код в Onfinish метода:Менеджер уведомлений не работает в счетчике таймера в android

public void onFinish() { 
      notificate(); 
      Log.i("Aler Resume", "Finished"); 
      remtime.setText("0 : 00 : 00"); 
      textCondition.setText(getString(R.string.BuddyAlertExpired)); 
       } 

В методе notificate() я писал:

private void notificate() { 
     NotificationManager notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

     Notification note = new Notification(R.drawable.ic_launcher, "New E-mail", System.currentTimeMillis()); 

     PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, AlertResume.class), 0); 
     note.setLatestEventInfo(this, "Buddy Alert", getString(R.string.BuddyAlertExpired), intent); 
     note.defaults= Notification.DEFAULT_VIBRATE; 
     note.defaults=Notification.DEFAULT_SOUND; 
     notifManager.notify(NOTIF_ID, note); 


    } 

Его прекрасно работать, когда я держу мое приложение открытым. Но когда я возвращаюсь из приложения, вызывается метод onfinish, и я вижу журнал корректно, но метод notofication не работает и не показывает никакого уведомления. Есть ли ошибка?

ответ

0

Когда вы уходите от приложения, может случиться так, что Android подумает, что ваш процесс запускает CountDown Timer как спам или дополнительный и не предназначен. и закончить его .. (Как будто вы забыли закрыть, позвольте мне закрыть)

Так лучше использовать AlarmManager для вышеуказанного материала, как установить PendingIntent - уведомление, в то время, когда вы наступаете на свой таймер ТАЙМЕРА ТАКЖЕ УВЕДОМЛЕНИЕ В ОТНОШЕНИИ НАМЕРЕНИЯ ИСПОЛЬЗОВАНИЯ МЕНЕДЖЕРА ТРЕВОГИ.

 nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
     Notification notification = new Notification(R.drawable.icon, "Test", System.currentTimeMillis()); 

     Intent intentTL = new Intent(context, MainActivity.class); 
     notification.setLatestEventInfo(context, "Test", "Do something!", 
       PendingIntent.getActivity(context, 0, intentTL, 
       PendingIntent.FLAG_CANCEL_CURRENT)); 
     notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; 
     nm.notify(1, notification); 

     AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
     PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, 
       intent, PendingIntent.FLAG_CANCEL_CURRENT); 
     am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, pendingIntent); 
Смежные вопросы