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