use of android.location.LocationManager in project JavaForFun by gumartinm.
the class NextActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CookieSyncManager.createInstance(this);
myCookie = CookieManager.getInstance().getCookie("192.168.1.34/userfront.php");
setContentView(R.layout.main2);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingAccuracy(Criteria.NO_REQUIREMENT);
criteria.setBearingRequired(false);
criteria.setCostAllowed(false);
criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
criteria.setSpeedAccuracy(Criteria.ACCURACY_LOW);
criteria.setSpeedRequired(true);
criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// 1. Fin out the provider state. (see Copilot.java code GPSLocationListener)
// 2. If it is TEMPORARILY_UNAVAILABLE:
// 2.1. locationManager.removeUpdates(locationListener); <--- Stop wasting GPS or GSM connections
// 2.2. Launch Timer with TimerTask 30 or 60 seconds before to enable the locationManager to find out if the provider status changed.
// 3. If OUT_OF_SERVICE
// 3.1. locationManager.removeUpdates(locationListener); <--- Stop wasting GPS or GSM connections
// 3.2. Launch Timer with TimerTask 30 or 60 seconds before to enable the locationManager to find out if the provider status changed.
// 4. If AVAILABLE
// Nothing to do here.
// Just when we are in the second or third point we have to stop draining battery because it is useless.
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(0, 10, criteria, locationListener, null);
}
use of android.location.LocationManager in project android-sdk-examples by IndoorAtlas.
the class MapsOverlayActivity method startListeningPlatformLocations.
private void startListeningPlatformLocations() {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (locationManager != null) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
}
}
use of android.location.LocationManager in project android-sdk-examples by IndoorAtlas.
the class WayfindingOverlayActivity method startListeningPlatformLocations.
private void startListeningPlatformLocations() {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (locationManager != null && (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
}
}
use of android.location.LocationManager in project actor-platform by actorapp.
the class MapPickerActivity method setUpMap.
/**
* This is where we can add markers or lines, add listeners or move the camera. In this case, we
* just add a marker near Africa.
* <p/>
* This should only be called once and when we are sure that {@link #mMap} is not null.
*/
private void setUpMap() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, PERMISSION_REQ_LOCATION);
im.actor.runtime.Log.d("Permissions", "MapPickerActivity.setUpMap - no permission :c");
return;
}
}
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
for (String provider : locationManager.getAllProviders()) {
currentLocation = locationManager.getLastKnownLocation(provider);
if (currentLocation != null) {
break;
}
}
if (currentLocation != null) {
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()), 14));
fetchPlaces(null);
}
mMap.setOnMyLocationChangeListener(this);
mMap.getUiSettings().setMyLocationButtonEnabled(false);
mMap.getUiSettings().setZoomControlsEnabled(false);
mMap.getUiSettings().setCompassEnabled(false);
mMap.setMyLocationEnabled(true);
mMap.setOnMapLongClickListener(this);
mMap.setOnMarkerClickListener(this);
}
use of android.location.LocationManager in project joynr by bmwcarit.
the class MyLocation method getLocation.
/**
* Get the location of the device
*
* @param context
* The android application environment
* @param result
* Callback that is called when the location is obtained
* @return true if the attempt to obtain the location starts successfully, false otherwise
*/
public boolean getLocation(Context context, LocationResult result) {
locationResult = result;
if (lm == null)
lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// exceptions will be thrown if provider is not permitted.
try {
gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
} catch (Exception ex) {
}
try {
network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
} catch (Exception ex) {
}
// don't start listeners if no provider is enabled
if (!gps_enabled && !network_enabled)
return false;
if (gps_enabled)
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
if (network_enabled)
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork);
// Set a timer, if this elapses without locationListenerGps or locationListenerNetwork being called
// then use the last known location
timer1 = new Timer();
timer1.schedule(new GetLastLocation(), 20000);
return true;
}
Aggregations