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.warp10.app.LocationService.java
/** * Function used to get the last location of user * @param isListenGPS if check GPS provider if available * @param isListenNetWork if check Network provider * @return Last known location//from w w w .j a va 2 s .c o m */ public static Location getLastLocation(boolean isListenGPS, boolean isListenNetWork) { Location mLastLocation = null; if (null != locManager) { if (isListenGPS) { if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { if (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(ctx, 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. return null; } mLastLocation = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); } else if (isListenNetWork) { mLastLocation = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } } else if (isListenNetWork) { mLastLocation = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } } return mLastLocation; }
From source file:com.mitre.holdshort.MainActivity.java
private void checkGPSSettings() { setContentView(R.layout.startup_screen); startMsg = (TextView) findViewById(R.id.startMsg); startButton = (Button) findViewById(R.id.startButton); startButton.setOnClickListener(enableGPSButtonListener); startProgress = (ProgressBar) findViewById(R.id.startProgress); if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) { startMsg.setText("Aquiring GPS Location..."); startProgress.setVisibility(View.VISIBLE); startButton.setVisibility(View.GONE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, locationListener); } else {/*from ww w .ja v a2s . c o m*/ startMsg.setText("This application requires the use of GPS."); startProgress.setVisibility(View.GONE); startButton.setVisibility(View.VISIBLE); } }
From source file:es.uja.photofirma.android.CameraActivity.java
/** * Controla los accesos y retornos a las aplicaciones de caputura de fotografas y '@firma', se establece * para cada caso tanto la situacion de exito como la de fracaso. */// ww w .jav a2 s. c om @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Vuelta de @firma, el resultCode indica exito o fracaso, en cada caso se toman unas medidas diferentes if (requestCode == CameraActivity.APP_FIRMA_REQUEST_CODE && resultCode == CameraActivity.RESULT_ERROR) { logger.appendLog(402, "el usuario deniega el uso del certificado"); showErrorHeader(); } //Vuelta de @firma, la firma fue realizada con exito, se almacena la ruta al archivo if (requestCode == CameraActivity.APP_FIRMA_REQUEST_CODE && resultCode == RESULT_OK) { logger.appendLog(200, "@firma realiz la firma adecuadamente"); signedFileLocation = data.getExtras().getString("signedfilelocation"); showSuccessHeader(); } //Si la captura de la fotografa tuvo exito if (requestCode == CameraActivity.REQUEST_IMAGE_CAPTURE & resultCode == RESULT_OK) { logger.appendLog(101, "el usuario captura foto"); //Se obtienen los datos del servicio de localizacin geografica LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); // Aade los geoTags a la foto realizada anteriormente if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && location != null) { PhotoCapture.addExifData(photoLocation, location); logger.appendLog(102, "el usuario aade exif"); logger.appendLog(103, "gps data: " + location); } logger.appendLog(104, "buscando @firma"); //Se comprueba si est la app @firma Intent intent = getPackageManager().getLaunchIntentForPackage("es.gob.afirma"); if (intent == null) { //Si no se encuentra instalada se notifica al usuario logger.appendLog(400, "@firma no instalada"); showErrorHeader(); errorText.setText(getString(R.string.camera_activity_no_afirma_present)); } else { //Si se encuentra, entonces se abre para dar comienzo al proceso de firma logger.appendLog(201, "abriendo @firma"); Intent i = new Intent(APP_FIRMA_OPEN_ACTION); i.putExtra(CameraActivity.APP_FIRMA_EXTRA_FILE_PATH, photoLocation); startActivityForResult(i, APP_FIRMA_REQUEST_CODE); } } //Si la captura de fotos fue cancelada if (requestCode == CameraActivity.REQUEST_IMAGE_CAPTURE && resultCode == CameraActivity.RESULT_CANCELED) { showInfoHeader(); logger.appendLog(105, "cierra la app de photo sin captura"); } //Si la captura de fotos fue cancelada if (requestCode == CameraActivity.REQUEST_IMAGE_CAPTURE && resultCode == CameraActivity.RESULT_ERROR) { showInfoHeader(); logger.appendLog(403, "Se produjo un error en la app de Cmara"); } }
From source file:com.mycompany.myfirstindoorsapp.PagedActivity.java
private void checkLocationIsEnabled() { // On android Marshmallow we also need to have active Location Services (GPS or Network based) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); boolean isNetworkLocationProviderEnabled = locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER); boolean isGPSLocationProviderEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); if (!isGPSLocationProviderEnabled && !isNetworkLocationProviderEnabled) { // Only if both providers are disabled we need to ask the user to do something Toast.makeText(this, "Location is off, enable it in system settings.", Toast.LENGTH_LONG).show(); Intent locationInSettingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); this.startActivityForResult(locationInSettingsIntent, REQUEST_CODE_LOCATION); } else {//from w ww . ja va 2 s.c o m continueLoading(); } } else { continueLoading(); } }
From source file:com.guidewithme.ArticleInfoListFragment.java
private Location getLocation() { Location loc = null;/* w ww . j a va 2s. c o m*/ if ((loc = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)) == null) loc = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); return loc; }
From source file:br.com.rescue_bots_android.bluetooth.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_blue); ActivityHelper.initialize(this); routeController = new RouteController(this); coordinates = new ArrayList<Path>(); trackerController = new TrackerController(this); Intent intent = getIntent();//from www .jav a 2s . c o m Bundle b = intent.getExtras(); mDevice = b.getParcelable(Homescreen.DEVICE_EXTRA); mDeviceUUID = UUID.fromString(b.getString(Homescreen.DEVICE_UUID)); mMaxChars = b.getInt(Homescreen.BUFFER_SIZE); Log.d(TAG, "Ready"); mBtnDisconnect = (Button) findViewById(R.id.btnDisconnect); mBtnSend = (Button) findViewById(R.id.btnSend); mBtnClear = (Button) findViewById(R.id.btnClear); mTxtReceive = (TextView) findViewById(R.id.txtReceive); mEditSend = (EditText) findViewById(R.id.editSend); scrollView = (ScrollView) findViewById(R.id.viewScroll); chkScroll = (CheckBox) findViewById(R.id.chkScroll); chkReceiveText = (CheckBox) findViewById(R.id.chkReceiveText); checkBoxJoystickEnable = (CheckBox) findViewById(R.id.checkBoxJoystickEnable); mBtnClearInput = (Button) findViewById(R.id.btnClearInput); mBtnConfig = (Button) findViewById(R.id.buttonConfig2); //imageButtonClaw (Button)findViewById(R.id.imageButtonClaw); editTextAngle = (TextView) findViewById(R.id.editTextAngle); joystickView = (JoystickView) findViewById(R.id.viewJoystick); //Event listener that always returns the variation of the angle in degrees, motion power in percentage and direction of movement ibClaw = (ImageButton) findViewById(R.id.imageButtonClaw); clawControll = new ClawControll(ibClaw); joystickView.setOnJoystickMoveListener(new OnJoystickMoveListener() { @Override public void onValueChanged(int angle, int power, int direction) { // TODO Auto-generated method stub mTxtReceive.append(" " + String.valueOf(angle) + ""); mTxtReceive.append(" " + String.valueOf(power) + "%"); switch (direction) { case JoystickView.FRONT: mTxtReceive.append("FRONT"); sendSerial("a"); break; case JoystickView.FRONT_RIGHT: mTxtReceive.append("FRONT_RIGHT"); sendSerial("c"); break; case JoystickView.RIGHT: mTxtReceive.append("RIGHT"); sendSerial("c"); break; case JoystickView.RIGHT_BOTTOM: mTxtReceive.append("RIGHT_BOTTOM"); sendSerial("f"); break; case JoystickView.BOTTOM: mTxtReceive.append("BOTTOM"); sendSerial("d"); break; case JoystickView.BOTTOM_LEFT: mTxtReceive.append("BOTTOM_LEFT"); sendSerial("e"); break; case JoystickView.LEFT: mTxtReceive.append("LEFT"); sendSerial("b"); break; case JoystickView.LEFT_FRONT: mTxtReceive.append("LEFT_FRONT"); sendSerial("b"); break; default: mTxtReceive.append("CENTER"); sendSerial("g"); } } }, JoystickView.DEFAULT_LOOP_INTERVAL); mTxtReceive.setMovementMethod(new ScrollingMovementMethod()); mBtnDisconnect.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mIsUserInitiatedDisconnect = true; new DisConnectBT().execute(); } }); mBtnSend.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { try { mBTSocket.getOutputStream().write(mEditSend.getText().toString().getBytes()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); mBtnClear.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mEditSend.setText(""); } }); mBtnClearInput.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { //mTxtReceive.setText(""); if (mBtnClearInput.getText().toString().equalsIgnoreCase(LocationManager.GPS_PROVIDER)) { mBtnClearInput.setText(LocationManager.NETWORK_PROVIDER); gps.setProvider(LocationManager.NETWORK_PROVIDER); } else { mBtnClearInput.setText(LocationManager.GPS_PROVIDER); gps.setProvider(LocationManager.GPS_PROVIDER); } } }); mBtnConfig.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent i = new Intent(MainActivity.this, ConfigActivity.class); startActivity(i); } }); ibClaw.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (clawControll != null) { clawControll.changeState(); } } }); checkBoxJoystickEnable.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (checkBoxJoystickEnable.isChecked()) { joystickEnabled = true; joystickView.setEnabled(true); ibClaw.setEnabled(true); } else { joystickEnabled = false; joystickView.setEnabled(false); ibClaw.setEnabled(false); } } }); joystickView.setEnabled(true); ibClaw.setEnabled(true); initGPSListener(); // initialize your android device sensor capabilities mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); image = (ImageView) findViewById(R.id.compassImg); }
From source file:com.jesjimher.bicipalma.MesProperesActivity.java
public void onLocationChanged(Location location) { // Slo hacer algo si la nueva ubicacin es mejor que la actual if (isBetterLocation(location, lBest)) { // Toast.makeText(getApplicationContext(), "Ubicacin encontrada", Toast.LENGTH_SHORT).show(); dRecuperaEst.setMessage(getString(R.string.recuperandolista)); // Actualizar precisin TextView pre = (TextView) this.findViewById(R.id.precisionNum); if (location.hasAccuracy()) pre.setText(String.format("%.0f m", location.getAccuracy())); else/*from w ww. j a v a 2s .c o m*/ pre.setText("Desconocida"); lBest = location; actualizarListado(); } else { //Toast.makeText(getApplicationContext(), "Ignorando ubicacin chunga", Toast.LENGTH_SHORT).show(); } // Si estamos en red y est el GPS activado, pasar a GPS // TODO: En API 9 se puede recibir un evento cuando se active el GPS. Investigar si se puede hacer con los modernos sin perder compatibilidad con API 8 if ((mUbic.equals(providerCoarse)) && (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))) activarUbicacion(); }
From source file:cd.education.data.collector.android.activities.GeoPointMapActivity.java
@Override protected void onResume() { super.onResume(); if (mRefreshLocation) { mLocationStatus.setVisibility(View.VISIBLE); if (mGPSOn) { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); }// w ww. j a v a 2 s . c o m if (mNetworkOn) { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } } }
From source file:com.tvs.signaltracker.STService.java
private void StartWorks() { InitForeground();//from ww w. j a v a 2s . c o m if (!CommonHandler.Configured | CommonHandler.dbman == null | CommonHandler.Signals == null) { CommonHandler.Configured = false; try { CommonHandler.dbman.Close(); } catch (Exception e) { } ; CommonHandler.dbman = null; CommonHandler.Signals = null; CommonHandler.ServiceRunning = false; CommonHandler.ServiceMode = 0; CommonHandler.KillService = true; try { this.stopSelf(); } catch (Exception e) { } ; Intent MainMenuIntent = new Intent().setClass(STService.this, SplashScreen.class); MainMenuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(MainMenuIntent); } else { if (CommonHandler.ServiceMode < 3) ServiceHandler.postDelayed(ReSendRun, 1000); if (CommonHandler.ServiceMode == 2 || CommonHandler.ServiceMode == 4) { InitBase(); GPSLocListener = new GPSLocationListener(); mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, CommonHandler.MinimumTime, CommonHandler.MinimumDistance / 10f, GPSLocListener); GPSs = new GPSStatusListener(); mlocManager.addGpsStatusListener(GPSs); showServiceNotification(); } else { ServiceHandler.post(LightMode); } if (CommonHandler.ServiceMode != 1 && CommonHandler.ServiceMode != 3) Toast.makeText(getApplicationContext(), getResources().getString(R.string.stservicestarted), Toast.LENGTH_LONG).show(); LocalRunning = true; } }
From source file:com.geoffreybuttercrumbs.arewethereyet.ZonePicker.java
public void onResume() { super.onResume(); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, updateRange, this); if (mMap.getMyLocation() != null && !everTouched) { mMap.animateCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(mMap.getMyLocation().getLatitude(), mMap.getMyLocation().getLongitude()), 14)); }/*from w ww .j av a2s. co m*/ }