Frage

I try to make my notification(from Service) updating or refreshing in every five minutes. How can I do this? This is, what i want to update.

if (...){

            int icon = R.drawable.updatedImage1;
            long when = System.currentTimeMillis();
            NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
            CharSequence message = "II Tydzień";        
            Notification notification = new Notification(icon, message, when );
            String title = this.getString(R.string.app_name); // Here you can pass the value of your TextView
            Intent notificationIntent = new Intent(this, MainActivity.class);
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
            PendingIntent intent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
            notification.setLatestEventInfo(this, title, message, intent);
            notification.flags |= Notification.FLAG_NO_CLEAR;
            notificationManager.notify(0, notification);  

} else { ...other notification }

Condition is period of time, so I need to change notification depending on what time is it.

War es hilfreich?

Lösung

You can use AlarmManager to schedule your notification repeatedly at different time intervals. The docs mention that:

This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running

You might be able to use setRepeating function for your purpose.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top