Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | package org.mozilla.gecko; |
michael@0 | 7 | |
michael@0 | 8 | import android.app.Notification; |
michael@0 | 9 | import android.app.Service; |
michael@0 | 10 | import android.content.Intent; |
michael@0 | 11 | import android.os.Binder; |
michael@0 | 12 | import android.os.IBinder; |
michael@0 | 13 | |
michael@0 | 14 | public class NotificationService extends Service { |
michael@0 | 15 | private final IBinder mBinder = new NotificationBinder(); |
michael@0 | 16 | private NotificationHandler mHandler; |
michael@0 | 17 | |
michael@0 | 18 | @Override |
michael@0 | 19 | public void onCreate() { |
michael@0 | 20 | // This has to be initialized in onCreate in order to ensure that the NotificationHandler can |
michael@0 | 21 | // access the NotificationManager service. |
michael@0 | 22 | mHandler = new NotificationHandler(this) { |
michael@0 | 23 | @Override |
michael@0 | 24 | protected void setForegroundNotification(int id, Notification notification) { |
michael@0 | 25 | super.setForegroundNotification(id, notification); |
michael@0 | 26 | |
michael@0 | 27 | if (notification == null) { |
michael@0 | 28 | stopForeground(true); |
michael@0 | 29 | } else { |
michael@0 | 30 | startForeground(id, notification); |
michael@0 | 31 | } |
michael@0 | 32 | } |
michael@0 | 33 | }; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | public class NotificationBinder extends Binder { |
michael@0 | 37 | NotificationService getService() { |
michael@0 | 38 | // Return this instance of NotificationService so clients can call public methods |
michael@0 | 39 | return NotificationService.this; |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | @Override |
michael@0 | 44 | public IBinder onBind(Intent intent) { |
michael@0 | 45 | return mBinder; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | public NotificationHandler getNotificationHandler() { |
michael@0 | 49 | return mHandler; |
michael@0 | 50 | } |
michael@0 | 51 | } |