aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaneren2005 <daneren2005@gmail.com>2013-04-04 15:13:25 -0700
committerdaneren2005 <daneren2005@gmail.com>2013-04-04 15:13:25 -0700
commit744547c3109891c6b4234341ed1f616a8593e993 (patch)
treeee8b0e855547a6fcc6671b74444bc8d212e179fc
parent2b4f5200ad10141fbb59d9d8d0c6a903d582a3df (diff)
downloaddsub-744547c3109891c6b4234341ed1f616a8593e993.tar.gz
dsub-744547c3109891c6b4234341ed1f616a8593e993.tar.bz2
dsub-744547c3109891c6b4234341ed1f616a8593e993.zip
Revert how notifications are handled, avoid service being killed
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java23
1 files changed, 16 insertions, 7 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
index 6e5d31a9..0a86baf8 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -113,7 +113,6 @@ public final class Util {
private final static Pair<Integer, Integer> NOTIFICATION_TEXT_COLORS = new Pair<Integer, Integer>();
private static Toast toast;
- private static int notificationID = 123512383;
private Util() {
}
@@ -644,7 +643,7 @@ public final class Util {
.show();
}
- public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, MusicDirectory.Entry song) {
+ public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song) {
// Set the icon, scrolling text and timestamp
final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(), System.currentTimeMillis());
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
@@ -662,8 +661,13 @@ public final class Util {
Intent notificationIntent = new Intent(context, DownloadActivity.class);
notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
- NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- manager.notify(notificationID, notification);
+
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ downloadService.startForeground(Constants.NOTIFICATION_ID_PLAYING, notification);
+ }
+ });
// Update widget
DSubWidgetProvider.getInstance().notifyChange(context, downloadService, true);
@@ -738,9 +742,14 @@ public final class Util {
rv.setOnClickPendingIntent(R.id.control_next, pendingIntent);
}
- public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService) {
- NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- manager.cancelAll();
+ public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler) {
+ // Remove notification and remove the service from the foreground
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ downloadService.stopForeground(true);
+ }
+ });
// Update widget
DSubWidgetProvider.getInstance().notifyChange(context, downloadService, false);