initial version
[headphoneindicator.git] / src / de / cweiske / headphoneindicator / BackgroundService.java
1 package de.cweiske.headphoneindicator;
2
3 import android.app.Service;
4 import android.content.Intent;
5 import android.content.IntentFilter;
6 import android.os.IBinder;
7
8 /**
9  * Permanent service that runs even when the app itself is stopped
10  *
11  * @author Christian Weiske, cweiske@cweiske.de
12  */
13 public class BackgroundService extends Service
14 {
15     protected NotificationReceiver notificationReceiver;
16
17     @Override
18     public void onCreate() {
19         super.onCreate();
20         IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
21         this.notificationReceiver = new NotificationReceiver();
22         registerReceiver(this.notificationReceiver, filter);
23     }
24
25     @Override
26     public void onDestroy() {
27         unregisterReceiver(this.notificationReceiver);
28     }
29
30     @Override
31     public IBinder onBind(Intent intent) {
32         return null;
33     }
34
35     @Override
36     public int onStartCommand(Intent intent, int flags, int startId) {
37         return START_STICKY;
38     }
39 }