-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMediaAndSensorService.java
More file actions
50 lines (40 loc) · 1.21 KB
/
Copy pathMediaAndSensorService.java
File metadata and controls
50 lines (40 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.thewhitewings.shaky.service;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import androidx.annotation.Nullable;
import com.thewhitewings.shaky.NotificationHandler;
/**
* Foreground service for Media and Sensor
*/
public class MediaAndSensorService extends Service {
private static final String TAG = "MediaAndSensorService";
private NotificationHandler notificationHandler;
@Override
public void onCreate() {
super.onCreate();
notificationHandler = new NotificationHandler(this);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
String action = intent.getAction();
if (Action.ACTIVATE.name().equals(action))
startForeground(1, notificationHandler.buildNotification());
else if (Action.DEACTIVATE.name().equals(action))
stopSelf();
}
return START_STICKY;
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
/**
* Actions to interact with MediaAndSensorService
*/
public enum Action {
ACTIVATE, DEACTIVATE
}
}