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:chat.client.gui.ChatActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); myNum = tm.getLine1Number();//w w w. ja v a 2 s . c om Bundle extras = getIntent().getExtras(); if (extras != null) { nickname = extras.getString("nickname"); } provider = LocationManager.GPS_PROVIDER; locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = locationManager.getLastKnownLocation(provider); locationManager.requestLocationUpdates(provider, 0, 0, new LocationListener() { @Override public void onLocationChanged(Location location) { // if (location != null) // updateWithNewLocation(location); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }); try { chatClientInterface = MicroRuntime.getAgent(nickname).getO2AInterface(ChatClientInterface.class); } catch (StaleProxyException e) { showAlertDialog(getString(R.string.msg_interface_exc), true); } catch (ControllerException e) { showAlertDialog(getString(R.string.msg_controller_exc), true); } myReceiver = new MyReceiver(); IntentFilter refreshChatFilter = new IntentFilter(); refreshChatFilter.addAction("jade.demo.chat.REFRESH_CHAT"); registerReceiver(myReceiver, refreshChatFilter); IntentFilter clearChatFilter = new IntentFilter(); clearChatFilter.addAction("jade.demo.chat.CLEAR_CHAT"); registerReceiver(myReceiver, clearChatFilter); setContentView(R.layout.chat); Button button = (Button) findViewById(R.id.button_send); button.setOnClickListener(buttonSendListener); TelephonyManager mgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); listener = new PhoneCallListener(); mgr.listen(listener, PhoneStateListener.LISTEN_CALL_STATE); }
From source file:com.nextgis.firereporter.SendReportActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.report);/*from w w w .j a v a 2 s . c o m*/ //add fragment FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); frCompass = (CompassFragment) getSupportFragmentManager().findFragmentByTag("COMPASS"); if (frCompass == null) { frCompass = new CompassFragment(); fragmentTransaction.add(R.id.compass_fragment_container, frCompass, "COMPASS").commit(); } getSupportFragmentManager().executePendingTransactions(); getSupportActionBar().setHomeButtonEnabled(true); edLatitude = (EditText) findViewById(R.id.edLatitude); edLongitude = (EditText) findViewById(R.id.edLongitude); edAzimuth = (EditText) findViewById(R.id.edAzimuth); edDistance = (EditText) findViewById(R.id.edDistance); edComment = (EditText) findViewById(R.id.edComment); edDistance.setText("100"); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (mLocationManager != null) { for (String aProvider : mLocationManager.getProviders(false)) { if (aProvider.equals(LocationManager.GPS_PROVIDER)) { gpsAvailable = true; } } if (gpsAvailable) { Location location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { float lat = (float) (location.getLatitude()); float lon = (float) (location.getLongitude()); edLatitude.setText(Float.toString(lat)); edLongitude.setText(Float.toString(lon)); } else { edLatitude.setText(getString(R.string.noLocation)); edLongitude.setText(getString(R.string.noLocation)); } mLocationListener = new LocationListener() { public void onStatusChanged(String provider, int status, Bundle extras) { switch (status) { case LocationProvider.OUT_OF_SERVICE: break; case LocationProvider.TEMPORARILY_UNAVAILABLE: break; case LocationProvider.AVAILABLE: break; } } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } public void onLocationChanged(Location location) { float lat = (float) (location.getLatitude()); float lon = (float) (location.getLongitude()); edLatitude.setText(Float.toString(lat)); edLongitude.setText(Float.toString(lon)); // FIXME: also need to calculate declination? } }; // location listener } else { edLatitude.setText(getString(R.string.noGPS)); edLongitude.setText(getString(R.string.noGPS)); edLatitude.setEnabled(false); edLongitude.setEnabled(false); } } mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); boolean accelerometerAvailable = false; boolean magnetometerAvailable = false; for (Sensor aSensor : mSensorManager.getSensorList(Sensor.TYPE_ALL)) { if (aSensor.getType() == Sensor.TYPE_ACCELEROMETER) { accelerometerAvailable = true; } else if (aSensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { magnetometerAvailable = true; } } compassAvailable = accelerometerAvailable && magnetometerAvailable; if (compassAvailable) { //frCompass = (CompassFragment) getSupportFragmentManager().findFragmentByTag("COMPASS"); if (frCompass != null) { frCompass.SetAzimuthCtrl(edAzimuth); } } else { edAzimuth.setText(getString(R.string.noCompass)); edAzimuth.setEnabled(false); } }
From source file:com.mruddy.devdataviewer.SensorFragment.java
/** * @see android.support.v4.app.Fragment#onResume() *///from w ww. java2s . co m @Override public void onResume() { super.onResume(); this.accelerometerTextView = (TextView) this.getActivity().findViewById(R.id.textViewAccelerometer); this.gpsTextView = (TextView) this.getActivity().findViewById(R.id.textViewGPS); this.sensorManager = (SensorManager) this.getActivity().getSystemService(Context.SENSOR_SERVICE); final Sensor accelerometerSensor = this.sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (null != accelerometerSensor) { this.accelerometerTextView.setText("waiting for data..."); this.sensorManager.registerListener(this, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL); } else { this.accelerometerTextView.setText("accelerometer not found"); } this.locationManager = (LocationManager) this.getActivity().getSystemService(Context.LOCATION_SERVICE); this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); }
From source file:com.mission_base.arviewer_android.viewer.ArvosPoi.java
/** * Returns the list of all objects to be drawn for the augment in the opengl * view.//from w ww.j a va 2 s . c om * * @param time * Returns the list of all objects to be drawn for the augment in * the opengl view. * @param result * The list to add the resulting objects to. * @param arvosObjects * The previous list of objects. */ public void getObjects(long time, List<ArvosObject> result, List<ArvosObject> arvosObjects) { float deviceLatitude = mInstance.mLatitude; float deviceLongitude = mInstance.mLongitude; float poiLatitude = 0f; float poiLongitude = 0f; float offsetX = 0f; float offsetZ = 0f; if (mLatitude != null) { poiLatitude = mLatitude; Location currentLocation = new Location(LocationManager.GPS_PROVIDER); currentLocation.setLatitude(deviceLatitude); Location poiLocation = new Location(LocationManager.GPS_PROVIDER); poiLocation.setLatitude(poiLatitude); offsetZ = currentLocation.distanceTo(poiLocation); if (deviceLatitude > poiLatitude) { if (offsetZ < 0) { offsetZ = -offsetZ; } } else { if (offsetZ > 0) { offsetZ = -offsetZ; } } } if (mLongitude != null) { poiLongitude = mLongitude; Location currentLocation = new Location(LocationManager.GPS_PROVIDER); currentLocation.setLongitude(deviceLongitude); Location poiLocation = new Location(LocationManager.GPS_PROVIDER); poiLocation.setLongitude(poiLongitude); offsetX = currentLocation.distanceTo(poiLocation); if (deviceLongitude > poiLongitude) { if (offsetX > 0) { offsetX = -offsetX; } } else { if (offsetX < 0) { offsetX = -offsetX; } } } HashSet<String> objectsToDraw = new HashSet<String>(); for (ArvosPoiObject poiObject : mPoiObjects) { ArvosObject arvosObject = poiObject.getObject(time, arvosObjects); if (arvosObject != null) { arvosObject.mPosition[0] += offsetX; arvosObject.mPosition[2] += offsetZ; objectsToDraw.add(arvosObject.mName); result.add(arvosObject); } } synchronized (mObjectsClicked) { for (ArvosPoiObject poiObject : mObjectsClicked) { poiObject.onClick(); } mObjectsClicked.clear(); } for (ArvosPoiObject poiObject : mObjectsToDeactivate) { poiObject.stop(); } mObjectsToDeactivate.clear(); for (ArvosPoiObject poiObject : mObjectsToStart) { poiObject.start(time); if (!objectsToDraw.contains(poiObject.mName)) { ArvosObject arvosObject = poiObject.getObject(time, arvosObjects); if (arvosObject != null) { objectsToDraw.add(arvosObject.mName); result.add(arvosObject); } } } mObjectsToStart.clear(); }
From source file:com.nextgis.mobile.forms.CompassFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // reference to vibrator service vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); // vibrate or not? SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); vibrationOn = prefs.getBoolean("compass_vibration", true); if (mCurrentLocation == null) { LocationManager locationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (mCurrentLocation == null) { mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); }/* w ww .java 2s . c o m*/ } mDeclination = 0; if (mCurrentLocation != null) { mDeclination = getDeclination(mCurrentLocation, System.currentTimeMillis()); } sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL); getActivity().registerReceiver(compassBroadcastReceiver, new IntentFilter(ACTION_COMPASS_UPDATES)); Log.d(TAG, "CompassActivity: onCreate"); }
From source file:ca.ualberta.cs.cmput301w15t04team04project.EditClaimActivity.java
/** *///from ww w . j a v a 2s .c om public void getClaimLocation(View view) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener); claimLocation = location; }
From source file:at.ac.tuwien.caa.docscan.camera.LocationHandler.java
private LocationHandler(Context context) { mContext = context;/*w w w . ja v a2 s . co m*/ mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { boolean stopManager = false; // Called when a new location is found: if (isBetterLocation(location, mLocation)) { mLocation = location; if (mLocation.getAccuracy() <= MIN_ACCURACY) stopManager = true; } if (System.currentTimeMillis() - mStartTime >= MAX_TIME_RUNNING) stopManager = true; if (stopManager && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) mLocationManager.removeUpdates(this); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { List<String> providers = mLocationManager.getProviders(true); if (providers.contains(LocationManager.NETWORK_PROVIDER)) mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, UPDATE_TIME, UPDATE_DISTANCE, locationListener); if (providers.contains(LocationManager.GPS_PROVIDER)) mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, UPDATE_TIME, UPDATE_DISTANCE, locationListener); mStartTime = System.currentTimeMillis(); } }
From source file:com.boundlessgeo.spatialconnect.scutilities.LocationHelper.java
/** * Convenience method to obtain the users last known location from the GPS or request the permission to do so if * it hasn't yet been granted.//from ww w .ja v a 2 s .c o m * * @return the last known Location instance or null if the permission was not granted */ private Location getLastKnownLocation() { if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { // check for permissions // http://developer.android.com/training/permissions/requesting.html if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { return locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); } else { ActivityCompat.requestPermissions((Activity) context, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION); } } return null; }
From source file:com.guidewithme.ArticleInfoListFragment.java
private void checkLocation() { if (System.currentTimeMillis() - sLastLocationRequestTime > LOCATION_UPDATE_INTERVAL) { // reqestSingleUpdate() listen for single update // and when get it will unsubscribe from LocationManager if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) mLocationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, this, null); if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) mLocationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, this, null); }/*w w w. j a v a 2 s. c o m*/ }
From source file:androidmapsdefinitivo.android.bajaintec.com.androidmapsdefinitivo.MapsActivity.java
@Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap;/*w ww . j ava2 s.c om*/ try { locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location == null) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, (LocationListener) this); location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location == null) { Log.d("Falla de gps: ", "valio"); location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } } CameraUpdate center = CameraUpdateFactory .newLatLng(new LatLng(location.getLatitude(), location.getLongitude())); /* CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(32.595085, -115.482046)); */ //CameraUpdate zoom = CameraUpdateFactory.zoomTo(20); mMap.moveCamera(center); //mMap.animateCamera(zoom); point = new LatLng(location.getAltitude(), location.getLongitude()); getLines(location.getAltitude(), location.getLongitude()); //getLines(); mMap.setMyLocationEnabled(true); mMap.getUiSettings().setZoomControlsEnabled(false); } catch (SecurityException e) { System.exit(0); } catch (NullPointerException e) { System.exit(0); } final Snackbar snackStart = Snackbar.make(findViewById(R.id.map), "Selecciona una ruta de una calle", Snackbar.LENGTH_LONG); snackStart.show(); final Snackbar snackErr = Snackbar.make(findViewById(R.id.map), "Selecciona una sola calle", Snackbar.LENGTH_LONG); final Snackbar snackbar = Snackbar.make(findViewById(R.id.map), R.string.guardar_ruta, Snackbar.LENGTH_LONG); mBtnGuardar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MapsActivity.this, SeguridadActivity.class); intent.putExtra("calle", calleDestino); intent.putExtra("origen_n", String.valueOf(markerPoints.get(0).latitude)); intent.putExtra("origen_w", String.valueOf(markerPoints.get(0).longitude)); intent.putExtra("destino_n", String.valueOf(markerPoints.get(1).latitude)); intent.putExtra("destino_w", String.valueOf(markerPoints.get(1).longitude)); intent.putExtra("idUsuario", getIntent().getIntExtra("idUsuario", 0)); startActivity(intent); } }); mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition cameraPosition) { LatLng li = cameraPosition.target; LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds; if (!bounds.contains(point)) { try { point = null; point = new LatLng(li.latitude, li.longitude); System.out.println("Sali"); getLines(point.latitude, point.longitude); //getLines(); } catch (SecurityException e) { e.printStackTrace(); } } } }); mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { @Override public void onMapClick(LatLng point) { if (markerPoints.size() > 1) { markerPoints.clear(); mMap.clear(); mBtnGuardar.setEnabled(false); //snackbar.dismiss(); getLines(); //getLines(point.latitude,point.longitude); } markerPoints.add(point); /* try { Geocoder gc = new Geocoder(getBaseContext(), Locale.getDefault()); List<Address> addresses = gc.getFromLocation(point.latitude, point.longitude, 1); //Obtener nombres de las calles. if (markerPoints.size() == 1) { calleOrigen = addresses.get(0).getAddressLine(0); } else if (markerPoints.size() == 2) { calleDestino = addresses.get(0).getAddressLine(0); } } catch (IOException e) { e.printStackTrace(); }*/ MarkerOptions options = new MarkerOptions(); options.position(point); if (markerPoints.size() == 1) { options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)); } else if (markerPoints.size() == 2) { options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)); if (!calleOrigen.equalsIgnoreCase(calleDestino)) { Log.d("Calles: ", calleOrigen + "//" + calleDestino); Boolean msj = !calleOrigen.equalsIgnoreCase(calleDestino); Log.d("Calles: ", msj.toString()); markerPoints.clear(); mMap.clear(); //getLines(point.latitude,point.longitude); getLines(); snackErr.show(); return; } } mMap.addMarker(options); if (markerPoints.size() >= 2) { LatLng origin = markerPoints.get(0); LatLng dest = markerPoints.get(1); String url = getDirectionsUrl(origin, dest); DownloadTask downloadTask = new DownloadTask(); downloadTask.execute(url); snackbar.show(); mBtnGuardar.setEnabled(true); } } }); //getLines(); getLines(point.latitude, point.longitude); }