android-ibc-forum

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

commit 784f5450e6bf21b1b89da2b004008d52e50be2da
parent f2fac604e11eb33e7f78060063b196e06e3005b0
Author: Jan Dankert <devnull@localhost>
Date:   Fri,  3 Feb 2012 23:58:10 +0100

Service umbenannt.

Diffstat:
src/de/mtbnews/android/service/SubscriptionService.java | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/de/mtbnews/android/service/UploadIntentService.java | 97-------------------------------------------------------------------------------
2 files changed, 97 insertions(+), 97 deletions(-)

diff --git a/src/de/mtbnews/android/service/SubscriptionService.java b/src/de/mtbnews/android/service/SubscriptionService.java @@ -0,0 +1,97 @@ +/** + * + */ +package de.mtbnews.android.service; + +import java.io.File; +import java.io.IOException; + +import android.app.IntentService; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.util.Log; +import de.mtbnews.android.NewsActivity; +import de.mtbnews.android.R; + +/** + * @author dankert + * + */ +public class SubscriptionService extends IntentService +{ + + public static final String EXTRA_REQUEST = "request"; + public static final String EXTRA_FILENAME = "file"; + private static final int NOTIFICATION_UPLOAD = 1; + + public SubscriptionService() + { + super("UploadIntentService"); + } + + /** + * + * {@inheritDoc} + * + * @see android.app.IntentService#onHandleIntent(android.content.Intent) + */ + @Override + protected void onHandleIntent(Intent intent) + { + final String filePath = intent.getStringExtra(EXTRA_FILENAME); + + final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + final Intent notificationIntent = new Intent(this, NewsActivity.class); + final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, + notificationIntent, 0); + + final File file = new File(filePath); + final String tickerText = getResources() + .getString(R.string.upload_long); + final Notification notification = new Notification( + R.drawable.ibc_logo, tickerText, System.currentTimeMillis()); + notification.setLatestEventInfo(getApplicationContext(), getResources() + .getString(R.string.upload), file.getName(), contentIntent); + notification.flags = Notification.FLAG_ONGOING_EVENT + | Notification.FLAG_NO_CLEAR; + nm.notify(NOTIFICATION_UPLOAD, notification); + + try + { + + // Alles OK. + final String msgText = getResources().getString(R.string.upload_ok); + notification.tickerText = getResources().getString( + R.string.upload_ok_long); + notification.setLatestEventInfo(getApplicationContext(), msgText, + file.getName(), contentIntent); + notification.flags = Notification.FLAG_AUTO_CANCEL; + nm.notify(NOTIFICATION_UPLOAD, notification); + Log.d(this.getClass().getName(), msgText); + throw new IOException(); + } + catch (IOException e) + { + // Fehler ist aufgetreten. + final String msgText = getResources().getString( + R.string.upload_fail); + notification.tickerText = getResources().getString( + R.string.upload_fail_long); + notification.setLatestEventInfo(getApplicationContext(), msgText, e + .getMessage() + + ": " + file.getName(), contentIntent); + notification.flags = Notification.FLAG_AUTO_CANCEL; + nm.notify(NOTIFICATION_UPLOAD, notification); + + Log.e(this.getClass().getName(), msgText, e); + } + finally + { + } + } + +} diff --git a/src/de/mtbnews/android/service/UploadIntentService.java b/src/de/mtbnews/android/service/UploadIntentService.java @@ -1,97 +0,0 @@ -/** - * - */ -package de.mtbnews.android.service; - -import java.io.File; -import java.io.IOException; - -import android.app.IntentService; -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.util.Log; -import de.mtbnews.android.NewsActivity; -import de.mtbnews.android.R; - -/** - * @author dankert - * - */ -public class UploadIntentService extends IntentService -{ - - public static final String EXTRA_REQUEST = "request"; - public static final String EXTRA_FILENAME = "file"; - private static final int NOTIFICATION_UPLOAD = 1; - - public UploadIntentService() - { - super("UploadIntentService"); - } - - /** - * - * {@inheritDoc} - * - * @see android.app.IntentService#onHandleIntent(android.content.Intent) - */ - @Override - protected void onHandleIntent(Intent intent) - { - final String filePath = intent.getStringExtra(EXTRA_FILENAME); - - final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - - final Intent notificationIntent = new Intent(this, NewsActivity.class); - final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, - notificationIntent, 0); - - final File file = new File(filePath); - final String tickerText = getResources() - .getString(R.string.upload_long); - final Notification notification = new Notification( - R.drawable.ibc_logo, tickerText, System.currentTimeMillis()); - notification.setLatestEventInfo(getApplicationContext(), getResources() - .getString(R.string.upload), file.getName(), contentIntent); - notification.flags = Notification.FLAG_ONGOING_EVENT - | Notification.FLAG_NO_CLEAR; - nm.notify(NOTIFICATION_UPLOAD, notification); - - try - { - - // Alles OK. - final String msgText = getResources().getString(R.string.upload_ok); - notification.tickerText = getResources().getString( - R.string.upload_ok_long); - notification.setLatestEventInfo(getApplicationContext(), msgText, - file.getName(), contentIntent); - notification.flags = Notification.FLAG_AUTO_CANCEL; - nm.notify(NOTIFICATION_UPLOAD, notification); - Log.d(this.getClass().getName(), msgText); - throw new IOException(); - } - catch (IOException e) - { - // Fehler ist aufgetreten. - final String msgText = getResources().getString( - R.string.upload_fail); - notification.tickerText = getResources().getString( - R.string.upload_fail_long); - notification.setLatestEventInfo(getApplicationContext(), msgText, e - .getMessage() - + ": " + file.getName(), contentIntent); - notification.flags = Notification.FLAG_AUTO_CANCEL; - nm.notify(NOTIFICATION_UPLOAD, notification); - - Log.e(this.getClass().getName(), msgText, e); - } - finally - { - } - } - -}