android-ibc-forum

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 83409690f998a84cf51fee567a17710db5043d4d
parent 2c77fefaaf79e4f5552c691f1c624419e4b3a35a
Author: Jan Dankert <devnull@localhost>
Date:   Thu, 17 May 2012 01:58:17 +0200

Notification während des Prüfens auf neue Nachrichten anzeigen.

Diffstat:
src/de/mtbnews/android/service/SubscriptionService.java | 28++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/de/mtbnews/android/service/SubscriptionService.java b/src/de/mtbnews/android/service/SubscriptionService.java @@ -57,6 +57,7 @@ public class SubscriptionService extends Service private SharedPreferences prefs; // Notification-Kategorien: + private static final int NOTIFICATION_EVENT_RUNNING = 1; private static final int NOTIFICATION_TOPIC = 2; private static final int NOTIFICATION_FORUM = 3; private static final int NOTIFICATION_MESSAGES = 4; @@ -117,7 +118,7 @@ public class SubscriptionService extends Service */ private class SubscriptionTask extends TimerTask { - public void run() + public void run() { Log.d(IBC.TAG, "timer event fired"); @@ -130,8 +131,26 @@ public class SubscriptionService extends Service final TapatalkClient client = new TapatalkClient( IBC.IBC_FORUM_CONNECTOR_URL); + // Anzeigen einer Notification, damit der Benutzer weiß, dass neue Nachrichten ab final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - + final PendingIntent emptyIntent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0); + + final String tickerText1 = getResources().getString( + R.string.checking_new); + + final Notification notificationRunning = new Notification(R.drawable.ibc_logo, + tickerText1, System.currentTimeMillis()); + + notificationRunning + .setLatestEventInfo(getApplicationContext(), getResources() + .getString(R.string.checking_new), + "", emptyIntent); + + notificationRunning.defaults = 0; + notificationRunning.flags = Notification.FLAG_ONGOING_EVENT + | Notification.FLAG_NO_CLEAR; + nm.notify(NOTIFICATION_EVENT_RUNNING, notificationRunning); + try { // Zuerst Login @@ -253,6 +272,11 @@ public class SubscriptionService extends Service Log.w(IBC.TAG, e); throw new RuntimeException("Unrecoverable error in service", e); } + finally + { + // In jedem Fall die Notification entfernen. + nm.cancel(NOTIFICATION_EVENT_RUNNING); + } } @Override