List of usage examples for android.content Context LOCATION_SERVICE
String LOCATION_SERVICE
To view the source code for android.content Context LOCATION_SERVICE.
Click Source Link
From source file:Main.java
/** Instantiates the mLocationManager variable if needed. */ private static final void loadLocationManager() { // TODO: Don't get Application context this way. Either pass in a static way of getting app context like in second line, or create a constructor to accept the context. if (mLocationManager == null) { mLocationManager = (LocationManager) (new Activity().getApplicationContext()) .getSystemService(Context.LOCATION_SERVICE); }/*from w ww. jav a2s. c o m*/ // if (mLocationManager == null) { mLocationManager = (LocationManager) MyApp.getContext().getSystemService(Context.LOCATION_SERVICE); } }
From source file:disono.webmons.com.utilities.sensor.GeoLocation.GPS.java
public LocationManager manager() { return (LocationManager) application.getSystemService(Context.LOCATION_SERVICE); }
From source file:it.feio.android.omninotes.utils.GeocodeHelper.java
public static LocationManager getLocationManager(Context context, final LocationListener locationListener) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // A check is done to avoid crash when NETWORK_PROVIDER is not // available (ex. on emulator with API >= 11) if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER) && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 50, locationListener); }/*from w w w. j a v a 2 s. c o m*/ if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER) && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 50, locationListener); } else { locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 60000, 50, locationListener); } return locationManager; }
From source file:com.mimming.sugarglider.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_sugar); floatingMap = (ImageView) findViewById(R.id.imageView1); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); }
From source file:com.mbapps.alibi.services.TrackingService.java
@Override public void onCreate() { super.onCreate(); this.trackingsKeeper = Database.getInstance(this); this.notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); this.locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); }
From source file:com.commonsware.android.geoweb2.GeoWebTwo.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main);// w ww . ja va2 s. c o m browser = (WebView) findViewById(R.id.webkit); myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); browser.getSettings().setJavaScriptEnabled(true); browser.addJavascriptInterface(new Locater(), "locater"); browser.loadUrl("file:///android_asset/geoweb2.html"); }
From source file:com.commonsware.android.geoweb.GeoWebOne.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main);/* w w w . ja v a2 s . c o m*/ browser = (WebView) findViewById(R.id.webkit); myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); browser.getSettings().setJavaScriptEnabled(true); browser.addJavascriptInterface(new Locater(), "locater"); browser.loadUrl("file:///android_asset/geoweb1.html"); }
From source file:com.example.techniche.locationaddress.MyLocation.java
public boolean getLocation(Context context, LocationResult result) { locationResult = result;// w ww. ja v a2 s. c o m this.context = context; 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) { if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. } else { lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps); } } if (network_enabled) lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork); timer1 = new Timer(); timer1.schedule(new GetLastLocation(), 20000); return true; }
From source file:a14n.geolocationdemo.MainActivity.java
private void requestLocationUpdates() { // 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) { JSONObject locationAsJson = new JSONObject(); try { locationAsJson.put("accuracy", location.getAccuracy()); locationAsJson.put("provider", location.getProvider()); locationAsJson.put("latitude", location.getLatitude()); locationAsJson.put("longitude", location.getLongitude()); locationAsJson.put("time", location.getTime()); } catch (JSONException e) { Log.e(TAG, "JSON exception", e); return; }/* w ww. j a va2 s.c om*/ flutterView.sendToFlutter("locations", locationAsJson.toString(), null); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); }
From source file:android.support.v7.app.TwilightManager.java
TwilightManager(Context context) {
mContext = context;
mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
}