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:edu.pdx.cecs.orcycle.MyApplication.java
private boolean isProviderEnabled() { final LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE); return manager.isProviderEnabled(LocationManager.GPS_PROVIDER); }
From source file:com.prey.activities.CheckPasswordActivity.java
@Override protected void onResume() { super.onResume(); bindPasswordControls();//from ww w .ja va 2 s . c o m TextView device_ready_h2_text = (TextView) findViewById(R.id.device_ready_h2_text); final TextView textForgotPassword = (TextView) findViewById(R.id.link_forgot_password); Button password_btn_login = (Button) findViewById(R.id.password_btn_login); EditText password_pass_txt = (EditText) findViewById(R.id.password_pass_txt); TextView textView1 = (TextView) findViewById(R.id.textView1); TextView textView2 = (TextView) findViewById(R.id.textView2); Typeface titilliumWebRegular = Typeface.createFromAsset(getAssets(), "fonts/Titillium_Web/TitilliumWeb-Regular.ttf"); Typeface titilliumWebBold = Typeface.createFromAsset(getAssets(), "fonts/Titillium_Web/TitilliumWeb-Bold.ttf"); Typeface magdacleanmonoRegular = Typeface.createFromAsset(getAssets(), "fonts/MagdaClean/magdacleanmono-regular.ttf"); textView1.setTypeface(magdacleanmonoRegular); textView2.setTypeface(magdacleanmonoRegular); device_ready_h2_text.setTypeface(titilliumWebRegular); textForgotPassword.setTypeface(titilliumWebBold); password_btn_login.setTypeface(titilliumWebBold); password_pass_txt.setTypeface(magdacleanmonoRegular); try { textForgotPassword.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { String url = PreyConfig.getPreyConfig(getApplicationContext()).getPreyPanelUrl(); Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url)); startActivity(browserIntent); } catch (Exception e) { } } }); } catch (Exception e) { } TextView textView5_1 = (TextView) findViewById(R.id.textView5_1); TextView textView5_2 = (TextView) findViewById(R.id.textView5_2); textView5_1.setTypeface(magdacleanmonoRegular); textView5_2.setTypeface(titilliumWebBold); TextView textViewUninstall = (TextView) findViewById(R.id.textViewUninstall); LinearLayout linearLayoutTour = (LinearLayout) findViewById(R.id.linearLayoutTour); textViewUninstall.setTypeface(titilliumWebBold); if (PreyConfig.getPreyConfig(getApplication()).getProtectTour()) { linearLayoutTour.setVisibility(View.GONE); textViewUninstall.setVisibility(View.VISIBLE); textViewUninstall.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String url = PreyConfig.getPreyConfig(getApplication()).getPreyUninstallUrl(); Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url)); startActivity(browserIntent); finish(); } }); } else { linearLayoutTour.setVisibility(View.VISIBLE); textViewUninstall.setVisibility(View.GONE); try { linearLayoutTour.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplication(), TourActivity1.class); Bundle b = new Bundle(); b.putInt("id", 1); intent.putExtras(b); startActivity(intent); finish(); } }); } catch (Exception e) { } } boolean showLocation = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { boolean canAccessFineLocation = PreyPermission.canAccessFineLocation(this); boolean canAccessCoarseLocation = PreyPermission.canAccessCoarseLocation(this); boolean canAccessCamera = PreyPermission.canAccessCamera(this); boolean canAccessReadPhoneState = PreyPermission.canAccessReadPhoneState(this); boolean canAccessReadExternalStorage = PreyPermission.canAccessReadExternalStorage(this); if (!canAccessFineLocation || !canAccessCoarseLocation || !canAccessCamera || !canAccessReadPhoneState || !canAccessReadExternalStorage) { AlertDialog.Builder builder = new AlertDialog.Builder(this); final FrameLayout frameView = new FrameLayout(this); builder.setView(frameView); final AlertDialog alertDialog = builder.create(); LayoutInflater inflater = alertDialog.getLayoutInflater(); View dialoglayout = inflater.inflate(R.layout.warning, frameView); TextView warning_title = (TextView) dialoglayout.findViewById(R.id.warning_title); TextView warning_body = (TextView) dialoglayout.findViewById(R.id.warning_body); warning_title.setTypeface(magdacleanmonoRegular); warning_body.setTypeface(titilliumWebBold); Button button_ok = (Button) dialoglayout.findViewById(R.id.button_ok); Button button_close = (Button) dialoglayout.findViewById(R.id.button_close); button_ok.setTypeface(titilliumWebBold); button_close.setTypeface(titilliumWebBold); final Activity thisActivity = this; button_ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PreyLogger.d("askForPermission"); askForPermission(); alertDialog.dismiss(); } }); button_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PreyLogger.d("close ask"); alertDialog.dismiss(); } }); alertDialog.show(); showLocation = false; } else { showLocation = true; } } else { showLocation = true; } if (showLocation) { LocationManager mlocManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); boolean isGpsEnabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNetworkEnabled = mlocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (isGpsEnabled || isNetworkEnabled) { PreyLogger.d("isGpsEnabled || isNetworkEnabled"); } else { PreyLogger.d("no gps ni red"); AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog alertDialog = builder.create(); TextView textview = new TextView(this); textview.setText(getString(R.string.location_settings)); textview.setMaxLines(10); textview.setTextSize(18F); textview.setPadding(20, 0, 20, 20); textview.setTextColor(Color.BLACK); builder.setView(textview); builder.setPositiveButton(getString(R.string.go_to_settings), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 0); return; } }); builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); } }); builder.create().show(); } } }
From source file:com.mibr.android.intelligentreminder.INeedToo.java
public void startListening() { if (mLocationManager != null) { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } else {//from w w w .j a v a2 s . c o m try { getLocationManager().requestLocationUpdates(LocationManager.GPS_PROVIDER, 20000, 10, this); getLocationManager().requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 20000, 10, this); } catch (Exception e44) { } } }
From source file:com.mendhak.gpslogger.GpsMainActivity.java
private void loadVersionSpecificProperties() { PackageInfo packageInfo;/* w ww . j a v a 2s . c o m*/ try { packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); int versionCode = packageInfo.versionCode; if (preferenceHelper.getLastVersionSeen() <= 71) { LOG.debug("preferenceHelper.getLastVersionSeen() " + preferenceHelper.getLastVersionSeen()); //Specifically disable passive provider... just once if (preferenceHelper.getChosenListeners().contains("passive")) { Set<String> listeners = new HashSet<>(); if (preferenceHelper.getChosenListeners().contains(LocationManager.GPS_PROVIDER)) { listeners.add(LocationManager.GPS_PROVIDER); } if (preferenceHelper.getChosenListeners().contains(LocationManager.NETWORK_PROVIDER)) { listeners.add(LocationManager.NETWORK_PROVIDER); } preferenceHelper.setChosenListeners(listeners); } } if (preferenceHelper.getLastVersionSeen() <= 74) { LOG.debug("preferenceHelper.getLastVersionSeen() " + preferenceHelper.getLastVersionSeen()); LOG.debug("Overriding minimum accuracy to 40"); if (preferenceHelper.getMinimumAccuracy() == 0) { preferenceHelper.setMinimumAccuracy(40); } } preferenceHelper.setLastVersionSeen(versionCode); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
From source file:com.google.android.apps.location.gps.gnsslogger.FileLogger.java
@Override public void onLocationChanged(Location location) { if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) { synchronized (mFileLock) { if (mFileWriter == null) { return; }//from ww w .j a v a 2 s . co m String locationStream = String.format(Locale.US, "Fix,%s,%f,%f,%f,%f,%f,%d", location.getProvider(), location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(), location.getAccuracy(), location.getTime()); try { mFileWriter.write(locationStream); mFileWriter.newLine(); } catch (IOException e) { logException(ERROR_WRITING_FILE, e); } } } }
From source file:com.application.treasurehunt.ScanQRCodeActivity.java
private void checkLocationServices() { //http://stackoverflow.com/questions/10311834/android-dev-how-to-check-if-location-services-are-enabled if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { mAlertForNoLocationServices = new Builder(ScanQRCodeActivity.this); mAlertForNoLocationServices.setTitle("Location Services"); mAlertForNoLocationServices/*www.j a v a 2 s. co m*/ .setMessage("Location services are not turned on. Turn on to track your treasure hunt."); mAlertForNoLocationServices.setCancelable(false); mAlertForNoLocationServices.setNegativeButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); mAlertForNoLocationServices.create(); mAlertForNoLocationServices.show(); } mLocationServicesChecked = true; }
From source file:com.cmput301w17t07.moody.MapsActivity.java
/** * Manipulates the map once available.// ww w . j av a 2s . c o m * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; //check the permission if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling Toast.makeText(getApplicationContext(), "Unable to access location." + " Please check your permissions", Toast.LENGTH_SHORT).show(); return; } filterFeeling = intent.getStringExtra("feelingFilter"); //------------------------- MAP FILTERS FOR USER'S MOODS ----------------------------------- if (user == 0) { if (filterFeeling.equals("all")) { try { moodArrayList = MoodController.getUserMoods(username, String.valueOf(0), MapsActivity.this, false, String.valueOf(100)); } catch (Exception e) { System.out.println("Error when trying to retrieve user's " + "location based mood history for all feelings" + e); } } else { ElasticMoodController.GetFeelingFilterMoods getFeelingFilterMoods = new ElasticMoodController.GetFeelingFilterMoods(); getFeelingFilterMoods.execute(username, filterFeeling); try { moodArrayList = getFeelingFilterMoods.get(); } catch (Exception e) { Log.i("error", "failed to get filtered feeling moods in map activity"); } } // Plotting of location based points on map for (int i = 0; i < moodArrayList.size(); i++) { Mood mood = moodArrayList.get(i); if (mood.getLongitude() == 0 && mood.getLatitude() == 0) { break; } else { double longitude; double latitude; longitude = moodArrayList.get(i).getLongitude(); latitude = moodArrayList.get(i).getLatitude(); LatLng tmp = new LatLng(latitude, longitude); mMap.addMarker(new MarkerOptions().position(tmp).title(mood.getFeeling()) .icon(BitmapDescriptorFactory.defaultMarker(setMarkerColor(mood.getFeeling())))); mMap.moveCamera(CameraUpdateFactory.newLatLng(tmp)); } } } //--------------------- MAP FILTERS FOR USER'S TIMELINE'S MOODS ---------------------------- else if (user == 1) { FollowController followController = new FollowController(); FollowingList followingList = followController.getFollowingList(username); if (filterFeeling.equals("all")) { try { moodArrayList = MoodController.getTimelineMoods(username, String.valueOf(0), MapsActivity.this); } catch (Exception e) { System.out.println("Error with getting timeline mood in MapsActivity" + e); } } else { nameList.addAll(followingList.getFollowingList()); try { for (int i = 0; i < nameList.size(); i++) { ElasticMoodController.GetFeelingFilterMoods getFeelingFilterMoods = new ElasticMoodController.GetFeelingFilterMoods(); getFeelingFilterMoods.execute(nameList.get(i).toString(), filterFeeling); try { moodArrayList.addAll(getFeelingFilterMoods.get()); } catch (Exception e) { System.out .println("Error with getting filtered" + " timeline moods in MapsActivity" + e); } } } catch (Exception e) { } } for (int j = 0; j < moodArrayList.size(); j++) { Mood mood = moodArrayList.get(j); if (mood.getLongitude() == 0 && mood.getLatitude() == 0) { break; } else { double longitude; double latitude; longitude = mood.getLongitude(); latitude = mood.getLatitude(); LatLng tmp = new LatLng(latitude, longitude); mMap.addMarker(new MarkerOptions().position(tmp).title(mood.getDisplayUsername()) .snippet(mood.getFeeling()) .icon(BitmapDescriptorFactory.defaultMarker(setMarkerColor(mood.getFeeling())))); mMap.moveCamera(CameraUpdateFactory.newLatLng(tmp)); } } } //--------------------------- ALL MOODS WITHIN 5KM OF THE USER ----------------------------- else if (user == 2) { locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); //check available tools List<String> locationList = locationManager.getProviders(true); if (locationList.contains(LocationManager.GPS_PROVIDER)) { provider = LocationManager.GPS_PROVIDER; } else if (locationList.contains(LocationManager.NETWORK_PROVIDER)) { provider = LocationManager.NETWORK_PROVIDER; } else { Toast.makeText(getApplicationContext(), "No map to use", Toast.LENGTH_LONG).show(); } location = locationManager.getLastKnownLocation(provider); if (location == null) { latitude = 0; longitude = 0; } else { latitude = location.getLatitude(); longitude = location.getLongitude(); } UserController userController = new UserController(); username = userController.readUsername(MapsActivity.this).toString(); ElasticMoodController.FilterMapByLocation filterMapByLocation = new ElasticMoodController.FilterMapByLocation(); filterMapByLocation.execute(location); try { currLocationArrayList.addAll(filterMapByLocation.get()); } catch (Exception e) { System.out.println("this is fff" + e); } for (int p = 0; p < currLocationArrayList.size(); p++) { Location locationNear = new Location("near"); locationNear.setLatitude(currLocationArrayList.get(p).getLatitude()); locationNear.setLongitude(currLocationArrayList.get(p).getLongitude()); float distance = location.distanceTo(locationNear); if (distance <= 5000.0) { currLocationArrayListWith5Km.add(currLocationArrayList.get(p)); } } for (int j = 0; j < currLocationArrayListWith5Km.size(); j++) { Mood mood = currLocationArrayListWith5Km.get(j); if (mood.getLongitude() == 0 && mood.getLatitude() == 0) { break; } else { double longitude; double latitude; longitude = mood.getLongitude(); latitude = mood.getLatitude(); LatLng tmp = new LatLng(latitude, longitude); mMap.addMarker(new MarkerOptions().position(tmp).title(mood.getDisplayUsername()) .snippet(mood.getFeeling()) .icon(BitmapDescriptorFactory.defaultMarker(setMarkerColor(mood.getFeeling())))); float zoomLevel = 12.0f; mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(tmp, zoomLevel)); } } } }
From source file:com.crearo.gpslogger.GpsMainActivity.java
private void loadVersionSpecificProperties() { PackageInfo packageInfo;//from www . j a v a 2s.c o m try { packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); int versionCode = packageInfo.versionCode; if (preferenceHelper.getLastVersionSeen() <= 71) { LOG.debug("preferenceHelper.getLastVersionSeen() " + preferenceHelper.getLastVersionSeen()); //Specifically disable passive provider... just once if (preferenceHelper.getChosenListeners().contains("passive")) { Set<String> listeners = new HashSet<>(); if (preferenceHelper.getChosenListeners().contains(LocationManager.GPS_PROVIDER)) { listeners.add(LocationManager.GPS_PROVIDER); } if (preferenceHelper.getChosenListeners().contains(LocationManager.NETWORK_PROVIDER)) { listeners.add(LocationManager.NETWORK_PROVIDER); } preferenceHelper.setChosenListeners(listeners); } } preferenceHelper.setLastVersionSeen(versionCode); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
From source file:digital.dispatch.TaxiLimoNewUI.GCM.GCMIntentService.java
private Location getBestLocation() { Location gpsLocation = getLocationByProvider(LocationManager.GPS_PROVIDER); Location networkLocation = getLocationByProvider(LocationManager.NETWORK_PROVIDER); Location tmpLocation;/*from w ww .jav a 2 s. c o m*/ if (gpsLocation == null) { Logger.v(TAG, "No GPS Location available."); return networkLocation; } if (networkLocation == null) { Logger.v(TAG, "No Network Location available"); return gpsLocation; } Logger.v(TAG, "GPS location:"); Logger.v(TAG, " accurate=" + gpsLocation.getAccuracy() + " time=" + gpsLocation.getTime()); Logger.v(TAG, "Netowrk location:"); Logger.v(TAG, " accurate=" + networkLocation.getAccuracy() + " time=" + networkLocation.getTime()); if (gpsLocation.getAccuracy() < networkLocation.getAccuracy()) { Logger.v(TAG, "use GPS location"); tmpLocation = gpsLocation; } else { Logger.v(TAG, "use networkLocation"); tmpLocation = networkLocation; } return tmpLocation; }
From source file:it.unipr.informatica.autobusparma.MappaFragment.java
private void updatePlaces() { locMan = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); Location lastLoc = getLocation(MIN_DISTANCE_CHANGE_FOR_UPDATES, MIN_TIME_BW_UPDATES); if (lastLoc != null) { double myLat = lastLoc.getLatitude(); double myLon = lastLoc.getLongitude(); LatLng myL = new LatLng(myLat, myLon); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myL, 15)); if (userMarker != null) userMarker.remove();//from w w w . j a v a 2s . c om String placesSearchStr = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + myLat + "," + myLon + "&radius=10000&sensor=true&keyword=autobus&key=INSERT KEY"; /*String placesSearchStr = null; Log.d("prova", "p"); try { placesSearchStr = leggiFiles(); } catch (IOException e) { // TODO Auto-generated catch block Log.d("prova", "sono nel catch"); e.printStackTrace(); }*/ //execute query new GetPlaces().execute(placesSearchStr); //onPostExecute(placesSearchStr); } if (isGPSEnabled) { locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); } }