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:Main.java
/** Returns the last known location latitude. Use this if you know that the location listener * doesn't need to turn on. This first tries GPS, then network, and returns 0.0 if GPS nor Network is enabled. */ public static final double getLastKnownLocationLatitude() { loadLocationManager();//from ww w .j a va 2 s. c o m double latitude = 0.0; // Load last known location coordinate, if available, so that user doesn't have to wait as long for a location. if (isGpsEnabled()) { Location gpsLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (gpsLocation != null) { latitude = gpsLocation.getLatitude(); } } else if (isNetworkEnabled()) { Location networkLocation = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (networkLocation != null) { latitude = networkLocation.getLatitude(); } } return latitude; }
From source file:Main.java
/** Returns the last known location longitude. Use this if you know that the location listener * doesn't need to turn on. This first tries GPS, then network, and returns 0.0 if GPS nor Network is enabled. */ public static final double getLastKnownLocationLongitude() { loadLocationManager();//from www .ja va 2 s .c o m double longitude = 0.0; // Load last known location coordinate, if available, so that user doesn't have to wait as long for a location. if (isGpsEnabled()) { Location gpsLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (gpsLocation != null) { longitude = gpsLocation.getLongitude(); } } else if (isNetworkEnabled()) { Location networkLocation = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (networkLocation != null) { longitude = networkLocation.getLongitude(); } } return longitude; }
From source file:Main.java
public static boolean isGPSEnable(Context context) { LocationManager locationMgr = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return locationMgr.isProviderEnabled(LocationManager.GPS_PROVIDER); }
From source file:Main.java
public static boolean isOpenGPS(Context context) { LocationManager alm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (!alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { return false; }//from ww w .java 2 s . c o m return true; }
From source file:Main.java
private static Location getLastBestLocation(Context pContext) { LocationManager locationManager = (LocationManager) pContext.getSystemService(Context.LOCATION_SERVICE); Location locationGPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location locationNet = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); long GPSLocationTime = 0; if (null != locationGPS) { GPSLocationTime = locationGPS.getTime(); }//from ww w .ja va2s . c om long NetLocationTime = 0; if (null != locationNet) { NetLocationTime = locationNet.getTime(); } if (0 < GPSLocationTime - NetLocationTime) { Log.e(TAG, "Located by GPS"); return locationGPS; } else { Log.e(TAG, "Located by network"); return locationNet; } }
From source file:com.prey.actions.location.LocationUtil.java
public static HttpDataService dataLocation(Context ctx) { HttpDataService data = null;/*w w w. j av a2s .c o m*/ try { LocationManager mlocManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); boolean isGpsEnabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNetworkEnabled = mlocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); PreyLogger.d("gps status:" + isGpsEnabled); PreyLogger.d("net status:" + isNetworkEnabled); PreyLocation location = null; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { if (isGpsEnabled || isNetworkEnabled) { String method = getMethod(isGpsEnabled, isNetworkEnabled); PreyLocation locationPlay = null; int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(ctx); if (ConnectionResult.SUCCESS == resultCode) { location = getPreyLocationPlayService(ctx, method); } } } else { PreyLogger.d("ask for permission location"); } if (location == null) location = getDataLocationWifi(ctx); if (location != null) { PreyLogger.d("locationData:" + location.getLat() + " " + location.getLng() + " " + location.getAccuracy()); data = convertData(location); } else { sendNotify(ctx, "Error"); } } catch (Exception e) { sendNotify(ctx, "Error"); } return data; }
From source file:Main.java
/** Returns true if GPS provider is enabled, otherwise false. */ public static final boolean isGpsEnabled() { loadLocationManager();// w ww . j av a2 s . com try { return mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception e) { // If exception occurs, then there is no GPS provider available. return false; } }
From source file:com.digzdigital.eservicedriver.SimplePositionProvider.java
public SimplePositionProvider(Context context, PositionListener listener) { super(context, listener); if (!type.equals(LocationManager.NETWORK_PROVIDER)) { type = LocationManager.GPS_PROVIDER; }// w w w . jav a 2 s .c om }
From source file:Main.java
public static boolean isOnlyGpsLocationModeEnabled(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int locationMode; try {/*from www . j av a 2s . c om*/ locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); } catch (Settings.SettingNotFoundException e) { return false; } // GPS must be enabled return Settings.Secure.LOCATION_MODE_SENSORS_ONLY == locationMode || Settings.Secure.LOCATION_MODE_HIGH_ACCURACY == locationMode; } else { String locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); if (TextUtils.isEmpty(locationProviders)) { return false; } String[] providers = locationProviders.split(","); for (String provider : providers) { // GPS must be enabled if (provider.equals(LocationManager.GPS_PROVIDER)) { return true; } } return false; } }
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); }/* w w w . j a va 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; }