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.dotd.mgrs.gps.MGRSLocationListener.java
public int onStartCommand(Intent intent, int flags, int startId) { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); sendMessageBroadcast(getString(R.string.acquiring)); return Service.START_NOT_STICKY; }
From source file:com.example.android.camera2video.CameraActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_camera); if (null == savedInstanceState) { getFragmentManager().beginTransaction().replace(R.id.container, Camera2VideoFragment.newInstance()) .commit();/* w ww . j a va2s .c o m*/ } mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, TAG_PERMISSION_FINE_LOCATION); } else { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0f, this); } mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(this, mAccSensor, SensorManager.SENSOR_DELAY_GAME); // mGraSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY); // mSensorManager.registerListener(this, mGraSensor, SensorManager.SENSOR_DELAY_GAME); // mLinSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION); // mSensorManager.registerListener(this, mLinSensor, SensorManager.SENSOR_DELAY_GAME); // mGyrSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); // mSensorManager.registerListener(this, mGyrSensor, SensorManager.SENSOR_DELAY_GAME); mUgySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE_UNCALIBRATED); mSensorManager.registerListener(this, mUgySensor, SensorManager.SENSOR_DELAY_GAME); // mMagSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); // mSensorManager.registerListener(this, mMagSensor, SensorManager.SENSOR_DELAY_GAME); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); mPowerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.acquire(); }
From source file:com.hoccer.api.android.LinccLocationManager.java
public void refreshLocation() throws UpdateException, ClientProtocolException, IOException { mLinccer.autoSubmitEnvironmentChanges(false); mLinccer.onWifiScanResults(mWifiManager.getScanResults()); Location location;// ww w . ja va2s . c om if (mNetworkProviderAvailable) { location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) mLinccer.onNetworkChanged(location); } location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) mLinccer.onGpsChanged(location); mLinccer.submitEnvironment(); }
From source file:android.support.v7.app.TwilightManager.java
private Location getLastKnownLocation() { Location coarseLoc = null;//from w ww . j a va2s. c o m Location fineLoc = null; int permission = PermissionChecker.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION); if (permission == PermissionChecker.PERMISSION_GRANTED) { coarseLoc = getLastKnownLocationForProvider(LocationManager.NETWORK_PROVIDER); } permission = PermissionChecker.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION); if (permission == PermissionChecker.PERMISSION_GRANTED) { fineLoc = getLastKnownLocationForProvider(LocationManager.GPS_PROVIDER); } if (fineLoc != null && coarseLoc != null) { // If we have both a fine and coarse location, use the latest return fineLoc.getTime() > coarseLoc.getTime() ? fineLoc : coarseLoc; } else { // Else, return the non-null one (if there is one) return fineLoc != null ? fineLoc : coarseLoc; } }
From source file:com.collectme.cordova.calgeolocation.CalGeolocation.java
/** * Check device settings for GPS./*from w w w .j a v a 2 s . c o m*/ * * @returns {boolean} The status of GPS in device settings. */ public boolean isGpsEnabled() { boolean result = isLocationProviderEnabled(LocationManager.GPS_PROVIDER); Log.d(TAG, "GPS enabled: " + result); return result; }
From source file:de.longri.cachebox3.AndroidPlatformConnector.java
@Override public void initialLocationReciver() { if (locationManager != null) { return;// w w w. j a v a 2s .c o m } locationListener = new AndroidLocationListener(); // GPS // Get the location manager locationManager = (LocationManager) this.application.getSystemService(Context.LOCATION_SERVICE); final int updateTime = 500; //500ms //TODO get gps updateTime from settings // int updateTime = Config.gpsUpdateTime.getValue(); // // Config.gpsUpdateTime.addChangedEventListener(new IChanged() { // // @Override // public void isChanged() { // int updateTime = Config.gpsUpdateTime.getValue(); // locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, 1, this); // } // }); application.runOnUiThread(new Runnable() { @Override public void run() { try { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, 1, locationListener); if (ActivityCompat.checkSelfPermission(AndroidPlatformConnector.this.application, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(AndroidPlatformConnector.this.application, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 300, locationListener); locationManager.addNmeaListener(locationListener); locationManager.addGpsStatusListener(locationListener); } catch (Exception e) { log.error("main.initialLocationManager()", e); e.printStackTrace(); } } }); }
From source file:com.mattprecious.locnotifier.LocationService.java
@Override public void onCreate() { super.onCreate(); LocationService.isRunning = true;/*from w ww . ja va2s . c om*/ preferences = PreferenceManager.getDefaultSharedPreferences(this); updateRunningNotification(); int lat = preferences.getInt("dest_lat", 0); int lng = preferences.getInt("dest_lng", 0); destination = new Location(""); destination.setLatitude(lat / 1E6); destination.setLongitude(lng / 1E6); radius = preferences.getFloat("dest_radius", 0); notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); locationListener = new LocationListener() { public void onLocationChanged(Location location) { Log.d(getClass().getSimpleName(), "Location changed"); updateLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); if (preferences.getBoolean("use_gps", false)) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); } Log.d(getClass().getSimpleName(), "Watching your location"); // creepy }
From source file:com.initiativaromania.hartabanilorpublici.IRUserInterface.map.IRLocationListener.java
/** * Resume location setup after permissions have been granted *//* w ww . j av a2s . c o m*/ public void setupLocation(boolean onResume) { this.locationManager = (LocationManager) act.getSystemService(Context.LOCATION_SERVICE); // Get GPS and network status boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (forceNetwork) isGPSEnabled = false; if (!isNetworkEnabled && !isGPSEnabled) { System.out.println("Cannot get loc"); return; } System.out.println("Can get loc"); try { if (isNetworkEnabled) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); if (onResume == false && locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); act.setInitialPosition(location); } } //end if if (isGPSEnabled) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); if (onResume == false && locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); act.setInitialPosition(location); } } } catch (SecurityException se) { System.out.println("Unable to resume location setup"); } }
From source file:tcc.iesgo.activity.ClientMapActivity.java
private void init() throws ClientProtocolException, IOException, JSONException { //Layout da aplicacao setContentView(R.layout.map);/*from w ww .java2 s. c om*/ //Instancia o mapView da aplicacao mapView = (MapView) findViewById(R.id.mapview); //Controladores de zoom mapView.setBuiltInZoomControls(true); //Instancia de overlays para o mapa mapOverlays = mapView.getOverlays(); //Controlador do mapa mc = mapView.getController(); mc.setZoom(16); //Obtem uma instacia do servico de gerenciador de localizacao lm = (LocationManager) getSystemService(LOCATION_SERVICE); //Ativa os updates para receber notificacoes de localizacao (periodicamente) lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 120000, 100f, ClientMapActivity.this); //timo local conhecido Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); // Cria um overlay mostrando a posicao do dispositivo myLocationOverlay = new MyCustomLocationOverlay(ClientMapActivity.this, mapView); // Habilita o ponto azul de localizacao na tela myLocationOverlay.enableMyLocation(); // Habilita atualizacoes do sensor myLocationOverlay.enableCompass(); // Adiciona o overlay no mapa mapOverlays.add(myLocationOverlay); dTaxi = ClientMapActivity.this.getResources().getDrawable(R.drawable.icon_taxi); mapInfo = (TextView) findViewById(R.id.map_info); showMap(location); }
From source file:com.androidquery.simplefeed.activity.PlaceActivity.java
private void refreshButton() { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); boolean enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); if (enabled) { aq.id(R.id.button_gps).gone();/*w ww. jav a 2 s . c om*/ } else { aq.id(R.id.button_gps).visible(); } refreshHint(); }