-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyService.java
More file actions
executable file
·50 lines (40 loc) · 1.45 KB
/
MyService.java
File metadata and controls
executable file
·50 lines (40 loc) · 1.45 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
package net.learn2develop.lbsreceiver_datalogging;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.IBinder;
import android.widget.Toast;
public class MyService extends Service {
LocationManager lm;
PendingIntent pendingIntent;
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
//---use the LocationManager class to obtain locations data---
lm = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
Intent i = new Intent(this, MyLocationReceiver.class);
pendingIntent = PendingIntent.getBroadcast(
this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
//---request for location updates using GPS---
lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
60000,
100,
pendingIntent);
return START_STICKY;
}
@Override
public void onDestroy() {
//---remove the pending intent---
lm.removeUpdates(pendingIntent);
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}