mobile/android/base/NotificationService.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/NotificationService.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +package org.mozilla.gecko;
    1.10 +
    1.11 +import android.app.Notification;
    1.12 +import android.app.Service;
    1.13 +import android.content.Intent;
    1.14 +import android.os.Binder;
    1.15 +import android.os.IBinder;
    1.16 +
    1.17 +public class NotificationService extends Service {
    1.18 +    private final IBinder mBinder = new NotificationBinder();
    1.19 +    private NotificationHandler mHandler;
    1.20 +
    1.21 +    @Override
    1.22 +    public void onCreate() {
    1.23 +        // This has to be initialized in onCreate in order to ensure that the NotificationHandler can
    1.24 +        // access the NotificationManager service.
    1.25 +        mHandler = new NotificationHandler(this) {
    1.26 +            @Override
    1.27 +            protected void setForegroundNotification(int id, Notification notification) {
    1.28 +                super.setForegroundNotification(id, notification);
    1.29 +
    1.30 +                if (notification == null) {
    1.31 +                    stopForeground(true);
    1.32 +                } else {
    1.33 +                    startForeground(id, notification);
    1.34 +                }
    1.35 +            }
    1.36 +        };
    1.37 +    }
    1.38 +
    1.39 +    public class NotificationBinder extends Binder {
    1.40 +        NotificationService getService() {
    1.41 +            // Return this instance of NotificationService so clients can call public methods
    1.42 +            return NotificationService.this;
    1.43 +        }
    1.44 +    }
    1.45 +
    1.46 +    @Override
    1.47 +    public IBinder onBind(Intent intent) {
    1.48 +        return mBinder;
    1.49 +    }
    1.50 +
    1.51 +    public NotificationHandler getNotificationHandler() {
    1.52 +        return mHandler;
    1.53 +    }
    1.54 +}

mercurial