-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
executable file
·94 lines (79 loc) · 2.92 KB
/
MainActivity.java
File metadata and controls
executable file
·94 lines (79 loc) · 2.92 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package net.learn2develop.lbsgps;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity {
LocationManager lm;
LocationListener locationListener;
private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc) {
if (loc != null) {
Toast.makeText(getBaseContext(),
"Location changed : Lat: " + loc.getLatitude() +
" Lng: " + loc.getLongitude(),
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(getBaseContext(),
"Provider: " + provider + " disabled",
Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(getBaseContext(),
"Provider: " + provider + " enabled",
Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
String statusString = "";
switch (status) {
case android.location.LocationProvider.AVAILABLE:
statusString = "available";
case android.location.LocationProvider.OUT_OF_SERVICE:
statusString = "out of service";
case
android.location.LocationProvider.TEMPORARILY_UNAVAILABLE:
statusString = "temporarily unavailable";
}
Toast.makeText(getBaseContext(),
provider + " " + statusString,
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//---use the LocationManager class to obtain locations data---
lm = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
}
@Override
public void onResume() {
super.onResume();
//---request for location updates using WiFi and Cellular
// triangulations---
lm.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
0,
0,
locationListener);
}
@Override
public void onDestroy() {
super.onDestroy();
//---remove the location listener---
lm.removeUpdates(locationListener);
}
}