summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-06-15 11:54:25 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-06-15 11:54:25 +0200
commitb24daa707f2ece590a95aa5561c578b4356a80cf (patch)
treec58850ecffb958e36c09e37a7014b31f1310790f /src/de
parentb5296e9f4da88536c92442e31be8ba22343c4e31 (diff)
downloadAntennaPod-b24daa707f2ece590a95aa5561c578b4356a80cf.zip
Implemented notification for Downloadservice
Diffstat (limited to 'src/de')
-rw-r--r--src/de/podfetcher/service/DownloadService.java29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/de/podfetcher/service/DownloadService.java b/src/de/podfetcher/service/DownloadService.java
index 90ddd73cd..c3f05e9d6 100644
--- a/src/de/podfetcher/service/DownloadService.java
+++ b/src/de/podfetcher/service/DownloadService.java
@@ -10,9 +10,14 @@ import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
+
+import de.podfetcher.activity.DownloadActivity;
+import de.podfetcher.activity.MediaplayerActivity;
import de.podfetcher.feed.*;
import de.podfetcher.storage.DownloadRequester;
import de.podfetcher.syndication.handler.FeedHandler;
+import android.R;
+import android.app.PendingIntent;
import android.app.Service;
import android.app.DownloadManager;
import android.content.Intent;
@@ -21,6 +26,9 @@ import android.media.MediaPlayer;
import android.os.IBinder;
import android.content.BroadcastReceiver;
import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.os.Handler;
import android.os.Message;
@@ -35,7 +43,8 @@ public class DownloadService extends Service {
private ExecutorService syncExecutor;
private DownloadRequester requester;
private FeedManager manager;
-
+ private NotificationCompat.Builder notificationBuilder;
+ private int NOTIFICATION_ID = 2;
/** Needed to determine the duration of a media file */
private MediaPlayer mediaplayer;
@@ -53,6 +62,7 @@ public class DownloadService extends Service {
manager = FeedManager.getInstance();
requester = DownloadRequester.getInstance();
mediaplayer = new MediaPlayer();
+ setupNotification();
}
@Override
@@ -97,6 +107,23 @@ public class DownloadService extends Service {
waiter.start();
}
+ private void setupNotification() {
+ PendingIntent pIntent = PendingIntent.getActivity(this, 0, new Intent(
+ this, DownloadActivity.class),
+ PendingIntent.FLAG_UPDATE_CURRENT);
+
+ Bitmap icon = BitmapFactory.decodeResource(null,
+ R.drawable.stat_notify_sync_noanim);
+ notificationBuilder = new NotificationCompat.Builder(this)
+ .setContentTitle("Downloading Podcast data")
+ .setContentText(requester.getNumberOfDownloads() + " Downloads left").setOngoing(true)
+ .setContentIntent(pIntent).setLargeIcon(icon)
+ .setSmallIcon(R.drawable.stat_notify_sync_noanim);
+
+ startForeground(NOTIFICATION_ID, notificationBuilder.getNotification());
+ Log.d(TAG, "Notification set up");
+ }
+
private BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {