List of usage examples for android.location LocationManager getProviders
public List<String> getProviders(boolean enabledOnly)
From source file:org.jraf.android.piclabel.app.form.FormActivity.java
private boolean getLatestLocalLocation(float[] latLon) { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = locationManager.getProviders(true); Location location = null;//from w w w . j a va 2 s. c o m for (int i = providers.size() - 1; i >= 0; i--) { location = locationManager.getLastKnownLocation(providers.get(i)); if (location != null) break; } if (location == null) return false; latLon[0] = (float) location.getLatitude(); latLon[1] = (float) location.getLongitude(); return true; }
From source file:com.alivenet.dmvtaxi.fragment.FragmentArriveDriver.java
public void getCurrentLocation(double latitude, double longitude) { googleMap = ((MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.maparrive)).getMap(); googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); googleMap.setMyLocationEnabled(true); LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(true); Location l = null;/* w w w . j a va2 s . c o m*/ if (googleMap != null) { googleMap.clear(); MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title(""); marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)); CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(latitude, longitude)) .zoom(10).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); googleMap.addMarker(marker); if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { } googleMap.setMyLocationEnabled(true); } if (latitude != 0.0d && longitude != 0.0d) { Intent intent = new Intent(getActivity(), BackgroundService.class); intent.putExtra("userid", mUserId); intent.putExtra("lat", String.valueOf(latitude)); intent.putExtra("long", String.valueOf(longitude)); getActivity().startService(intent); } }
From source file:system.info.reader.java
public String refresh() { //wifi/* w w w.j av a2 s . c o m*/ WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if ((wifiInfo != null) && (wifiInfo.getMacAddress() != null)) Properties.setInfo((String) propertyItems[4], wifiInfo.getMacAddress()); else Properties.setInfo((String) propertyItems[4], "not avaiable"); //String tmpsdcard = runCmd("df", ""); //if (tmpsdcard != null) result += tmpsdcard + "\n\n"; //setMap("dpi", dpi); //location LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); List ll = lm.getProviders(true); Boolean foundLoc = false; for (int i = 0; i < ll.size(); i++) { Location lo = lm.getLastKnownLocation((String) ll.get(i)); if (lo != null) { Properties.setInfo((String) propertyItems[3], lo.getLatitude() + ":" + lo.getLongitude()); foundLoc = true; break; } } if (!foundLoc) Properties.setInfo((String) propertyItems[3], getString(R.string.locationHint)); ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List serviceList = am.getRunningServices(10000); serviceInfo = ""; for (int i = 0; i < serviceList.size(); i++) { RunningServiceInfo rs = (RunningServiceInfo) serviceList.get(i); serviceInfo += rs.service.flattenToShortString() + "\n"; } //result += getString(R.string.nService) + serviceList.size() + "\n";//service number psInfo = ""; List appList = am.getRunningAppProcesses(); for (int i = 0; i < appList.size(); i++) { RunningAppProcessInfo as = (RunningAppProcessInfo) appList.get(i); psInfo += as.processName + "\n"; } //result += getString(R.string.nProcess) + appList.size() + "\n";//process number taskInfo = ""; List taskList = am.getRunningTasks(10000); for (int i = 0; i < taskList.size(); i++) { RunningTaskInfo ts = (RunningTaskInfo) taskList.get(i); taskInfo += ts.baseActivity.flattenToShortString() + "\n"; } //result += getString(R.string.nTask) + taskList.size() + "\n\n";//task number //result += getString(R.string.nProcess) + runCmd("ps", "") + "\n";//process number //setMap(getString(R.string.nApk), nApk); //send message to let view redraw. Message msg = mRedrawHandler.obtainMessage(); mRedrawHandler.sendMessage(msg); //properListItemAdapter.notifyDataSetChanged();//no use? Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(400); return ""; }
From source file:edu.pdx.cecs.orcycle.MyApplication.java
public Location getLastKnownLocation() { LocationManager lm = null; List<String> providers = null; Location location = null;/*from w ww.j a v a 2s . co m*/ if (null != (lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE))) { if (null != (providers = lm.getProviders(true))) { /* Loop over the array backwards, and if you get a location, then break out the loop*/ for (int i = providers.size() - 1; i >= 0; --i) { if (null != (location = lm.getLastKnownLocation(providers.get(i)))) { break; } } } } return location; }
From source file:org.odk.collect.android.activities.GeoTraceOsmMapActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.geotrace_osm_layout); setTitle(getString(R.string.geotrace_title)); // Setting title of the action mapView = (MapView) findViewById(R.id.geotrace_mapview); helper = new MapHelper(this, mapView, GeoTraceOsmMapActivity.this); mapView.setMultiTouchControls(true); mapView.setBuiltInZoomControls(true); mapView.getController().setZoom(zoomLevel); myLocationOverlay = new MyLocationNewOverlay(mapView); inflater = this.getLayoutInflater(); traceSettingsView = inflater.inflate(R.layout.geotrace_dialog, null); polygonPolylineView = inflater.inflate(R.layout.polygon_polyline_dialog, null); timeDelay = (Spinner) traceSettingsView.findViewById(R.id.trace_delay); timeDelay.setSelection(3);//from ww w. j a va2 s.com timeUnits = (Spinner) traceSettingsView.findViewById(R.id.trace_scale); layersButton = (ImageButton) findViewById(R.id.layers); layersButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { helper.showLayersDialog(GeoTraceOsmMapActivity.this); } }); locationButton = (ImageButton) findViewById(R.id.show_location); locationButton.setEnabled(false); locationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { reset_trace_settings(); showZoomDialog(); } }); clearButton = (ImageButton) findViewById(R.id.clear); clearButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showClearDialog(); } }); ImageButton saveButton = (ImageButton) findViewById(R.id.geotrace_save); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mapMarkers.size() != 0) { alertDialog.show(); } else { saveGeoTrace(); } } }); if (mapMarkers == null || mapMarkers.size() == 0) { clearButton.setEnabled(false); } manualCaptureButton = (Button) findViewById(R.id.manual_button); manualCaptureButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { addLocationMarker(); } }); pauseButton = (ImageButton) findViewById(R.id.pause); playButton = (ImageButton) findViewById(R.id.play); playButton.setEnabled(false); beenPaused = false; traceMode = 1; playButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { if (!playCheck) { if (!beenPaused) { alert.show(); } else { RadioGroup rb = (RadioGroup) traceSettingsView.findViewById(R.id.radio_group); int radioButtonID = rb.getCheckedRadioButtonId(); View radioButton = rb.findViewById(radioButtonID); traceMode = rb.indexOfChild(radioButton); if (traceMode == 0) { setupManualMode(); } else if (traceMode == 1) { setupAutomaticMode(); } else { reset_trace_settings(); } } playCheck = true; } else { playCheck = false; startGeoTrace(); } } }); pauseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { playButton.setVisibility(View.VISIBLE); if (mapMarkers != null && mapMarkers.size() > 0) { clearButton.setEnabled(true); } pauseButton.setVisibility(View.GONE); manualCaptureButton.setVisibility(View.GONE); playCheck = true; modeActive = false; myLocationOverlay.disableFollowLocation(); try { schedulerHandler.cancel(true); } catch (Exception e) { // Do nothing } } }); overlayMapLayerListener(); buildDialogs(); Intent intent = getIntent(); if (intent != null && intent.getExtras() != null) { if (intent.hasExtra(GeoTraceWidget.TRACE_LOCATION)) { String s = intent.getStringExtra(GeoTraceWidget.TRACE_LOCATION); playButton.setEnabled(false); clearButton.setEnabled(true); overlayIntentTrace(s); locationButton.setEnabled(true); //zoomToCentroid(); zoomToBounds(); } } else { myLocationOverlay.runOnFirstFix(centerAroundFix); } Button polygonSaveButton = (Button) polygonPolylineView.findViewById(R.id.polygon_save); polygonSaveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mapMarkers.size() > 2) { createPolygon(); alertDialog.dismiss(); saveGeoTrace(); } else { alertDialog.dismiss(); showPolygonErrorDialog(); } } }); Button polylineSaveButton = (Button) polygonPolylineView.findViewById(R.id.polyline_save); polylineSaveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); saveGeoTrace(); } }); zoomDialogView = getLayoutInflater().inflate(R.layout.geoshape_zoom_dialog, null); zoomLocationButton = (Button) zoomDialogView.findViewById(R.id.zoom_location); zoomLocationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { zoomToMyLocation(); mapView.invalidate(); zoomDialog.dismiss(); } }); zoomPointButton = (Button) zoomDialogView.findViewById(R.id.zoom_shape); zoomPointButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //zoomToCentroid(); zoomToBounds(); mapView.invalidate(); zoomDialog.dismiss(); } }); mapView.invalidate(); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = locationManager.getProviders(true); for (String provider : providers) { if (provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER)) { locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); gpsOn = true; } if (provider.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)) { locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); networkOn = true; } } if (gpsOn) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } if (networkOn) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } }
From source file:org.pouyadr.ui.LocationActivity.java
private Location getLastLocation() { LocationManager lm = (LocationManager) ApplicationLoader.applicationContext .getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(true); Location l = null;//from w w w . j a v a2 s .c o m for (int i = providers.size() - 1; i >= 0; i--) { // l = lm.getLastKnownLocation(providers.get(i)); if (l != null) { break; } } return l; }
From source file:pandroid.agent.PandroidAgentListener.java
private void gpsLocation() { // Starts with GPS, if no GPS then gets network location // /* ww w . jav a 2 s . c o m*/ LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(true); Log.d("PANDROID providers count", "" + providers.size()); /* Loop over the array backwards, and if you get an accurate location, then break out the loop*/ Location loc = null; for (int i = providers.size() - 1; i >= 0; i--) { Log.d("PANDROID providers", providers.get(i)); loc = lm.getLastKnownLocation(providers.get(i)); if (loc != null) break; } if (loc != null) { Log.d("PANDROID", "loc != null"); //if(latitude != loc.getLatitude() || longitude != loc.getLongitude()) { lastGpsContactDateTime = getHumanDateTime(-1); //`} Log.d("LATITUDE", Double.valueOf(loc.getLatitude()).toString()); Log.d("LONGITUDE", Double.valueOf(loc.getLongitude()).toString()); putSharedData("PANDROID_DATA", "latitude", Double.valueOf(loc.getLatitude()).toString(), "float"); putSharedData("PANDROID_DATA", "longitude", Double.valueOf(loc.getLongitude()).toString(), "float"); } Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); String bestProvider = lm.getBestProvider(criteria, true); // If not provider found, abort GPS retrieving if (bestProvider == null) { Log.e("LOCATION", "No location provider found!"); return; } lm.requestLocationUpdates(bestProvider, Core.interval, 15, new LocationListener() { public void onLocationChanged(Location location) { Log.d("Best latitude", Double.valueOf(location.getLatitude()).toString()); putSharedData("PANDROID_DATA", "latitude", Double.valueOf(location.getLatitude()).toString(), "float"); Log.d("Best longitude", Double.valueOf(location.getLongitude()).toString()); putSharedData("PANDROID_DATA", "longitude", Double.valueOf(location.getLongitude()).toString(), "float"); } public void onStatusChanged(String s, int i, Bundle bundle) { } public void onProviderEnabled(String s) { // try switching to a different provider } public void onProviderDisabled(String s) { putSharedData("PANDROID_DATA", "enabled_location_provider", "disabled", "string"); } }); //} }
From source file:com.androzic.Androzic.java
/** * Retrieves last known location without enabling location providers. * @return Most precise last known location or null if it is not available *//*w w w. ja v a 2s . c o m*/ public Location getLastKnownSystemLocation() { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(true); Location l = null; for (int i = providers.size() - 1; i >= 0; i--) { l = lm.getLastKnownLocation(providers.get(i)); if (l != null) break; } return l; }