-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyLocationReceiver.java
More file actions
executable file
·42 lines (37 loc) · 1.53 KB
/
MyLocationReceiver.java
File metadata and controls
executable file
·42 lines (37 loc) · 1.53 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
package net.learn2develop.lbsreceiver_datalogging;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.widget.Toast;
public class MyLocationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String locationKey = LocationManager.KEY_LOCATION_CHANGED;
String providerEnabledKey = LocationManager.KEY_PROVIDER_ENABLED;
if (intent.hasExtra(providerEnabledKey)) {
if (!intent.getBooleanExtra(providerEnabledKey, true)) {
Toast.makeText(context,
"Provider disabled",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context,
"Provider enabled",
Toast.LENGTH_SHORT).show();
}
}
if (intent.hasExtra(locationKey)) {
Location loc = (Location)intent.getExtras().get(locationKey);
Toast.makeText(context,
"Location changed : Lat: " + loc.getLatitude() +
" Lng: " + loc.getLongitude(),
Toast.LENGTH_SHORT).show();
DBAdapter db = new DBAdapter(context);
db.open();
db.insertLocation(String.valueOf(loc.getLatitude()),
String.valueOf(loc.getLongitude()));
db.close();
}
}
}