List of usage examples for android.location LocationManager GPS_PROVIDER
String GPS_PROVIDER
To view the source code for android.location LocationManager GPS_PROVIDER.
Click Source Link
From source file:com.lixplor.fastutil.utils.control.GpsUtil.java
public static boolean isGpsEnabled() { return sLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); }
From source file:com.digzdigital.eservicedriver.MixedPositionProvider.java
public void startUpdates() { lastFixTime = System.currentTimeMillis(); locationManager.addGpsStatusListener(this); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, period, 0, this); }
From source file:com.example.techniche.locationaddress.MyLocation.java
public boolean getLocation(Context context, LocationResult result) { locationResult = result;/*w w w . ja v a 2s .c om*/ 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:com.daoofdev.weatherday.LocationWrapper.java
private static String getPreferredProvider() { if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) return LocationManager.GPS_PROVIDER; if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) return LocationManager.NETWORK_PROVIDER; return null;// w w w . j a va 2 s . co m }
From source file:com.lauszus.launchpadflightcontrollerandroid.app.MapFragment.java
@Override public void onResume() { super.onResume(); LocationManager locationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { new AlertDialog.Builder(getActivity()) .setMessage("Your GPS seems to be disabled, do you want to enable it?").setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); }/* w w w . j a v a 2 s. c o m*/ }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int id) { dialog.cancel(); Toast.makeText(getActivity(), "GPS must be on in order to use this application!", Toast.LENGTH_LONG).show(); getActivity().finish(); } }).create().show(); } else { setUpMapIfNeeded(); if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { Location location = locationManager .getLastKnownLocation(locationManager.getBestProvider(new Criteria(), false)); if (location != null) { LatLng myLocation = new LatLng(location.getLatitude(), location.getLongitude()); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myLocation, 19.0f)); } } } }
From source file:com.commonsware.android.weather.WeatherFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true);/*from w w w . j av a 2s. c o m*/ getActivity().getApplicationContext().bindService(new Intent(getActivity(), WeatherService.class), this, Context.BIND_AUTO_CREATE); mgr = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); mgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3600000, 1000, this); }
From source file:disono.webmons.com.utilities.sensor.GeoLocation.GPS.java
public void runOnce(LocationListener listener) { if (ActivityCompat.checkSelfPermission(application, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(application, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Log.e(TAG, "GPS is not available or enabled on this device."); return;// w w w .ja v a2s. co m } this.manager().requestSingleUpdate(LocationManager.GPS_PROVIDER, listener, null); }
From source file:MyActivity.java
@Override protected void onResume() { super.onResume(); sensorManager.registerListener(sensorListener, magFieldSensor, SensorManager.SENSOR_DELAY_UI); sensorManager.registerListener(sensorListener, accelerometer, SensorManager.SENSOR_DELAY_UI); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); }
From source file:ca.ualberta.cs.drivr.GPSTracker.java
/** * Gets the User Current Location through GPS or Wifi * @return returns user current Location. */// w w w. jav a 2s .c o m public Location getLocation() { try { locationManger = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); // Check that App can get Location isGPSEnabled = locationManger.isProviderEnabled(LocationManager.GPS_PROVIDER); isNetworkEnabled = locationManger.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!isGPSEnabled && !isNetworkEnabled) { // Services not Enabled enableGPS(); } else { this.canGetLocation = true; if (isNetworkEnabled) { location = null; if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { locationManger.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 1, this); if (locationManger != null) { location = locationManger.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { myLatitude = location.getLatitude(); myLongitude = location.getLongitude(); } } } } if (isGPSEnabled) { location = null; if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { locationManger.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, this); if (locationManger != null) { location = locationManger.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { myLatitude = location.getLatitude(); myLongitude = location.getLongitude(); } } } } } } catch (Exception e) { e.printStackTrace(); } if (myLocation != null) { return myLocation; } else { // Android Emulator Can't Use Wifi myLocation = new Location("Edmonton"); myLocation.setLatitude(53.5232); myLocation.setLongitude(-113.5263); myLatitude = myLocation.getLatitude(); myLongitude = myLocation.getLongitude(); return myLocation; } }
From source file:com.commonsware.android.location.background.LocationPollerService.java
@SuppressWarnings("MissingPermission") @Override/*www. j ava2 s .co m*/ public void onCreate() { super.onCreate(); prefs = PreferenceManager.getDefaultSharedPreferences(this); mgr = (LocationManager) getSystemService(LOCATION_SERVICE); String delay = prefs.getString(PREF_DELAY, "60000"); mgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, Integer.parseInt(delay), 0, this); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1 && prefs.getBoolean(PREF_FOREGROUND, false)) { startForeground(NOTIFY_ID, buildNotification(this)); } }