List of usage examples for android.location LocationManager NETWORK_PROVIDER
String NETWORK_PROVIDER
To view the source code for android.location LocationManager NETWORK_PROVIDER.
Click Source Link
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;//from w w w . j av a 2s. c o m 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:com.simadanesh.isatis.CommonPlace.java
public void StartLocationManager(Context context) { if (locationManager == null) { locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); }/*from w w w . j av a 2 s. c om*/ }
From source file:com.mattprecious.locnotifier.LocationService.java
@Override public void onCreate() { super.onCreate(); LocationService.isRunning = true;//from ww w .j a v a2 s . com 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.app.swaedes.swaedes.GPSTracker.java
public Location getLocation() { if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(mContext, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(mContext, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return null; } else {/*from ww w . j a v a 2 s . c o m*/ try { locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); // getting GPS status isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); // getting network status isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!isGPSEnabled && !isNetworkEnabled) { // no network provider is enabled } else { this.canGetLocation = true; // First get location from Network Provider if (isNetworkEnabled) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); Log.d("Network", "Network"); if (locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); } } } // if GPS Enabled get lat/long using GPS Services if (isGPSEnabled) { if (location == null) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); Log.d("GPS Enabled", "GPS Enabled"); if (locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); } } } } } } catch (Exception e) { e.printStackTrace(); } return location; } }
From source file:com.example.android.uvdemo.MainActivity.java
@Override protected void onResume() { if (initLocationProvider()) { mLocMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 100, this); Location location = this.mLocMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) this.onLocationChanged(location); }//ww w . ja v a 2s.com getAddressThread(); super.onResume(); }
From source file:eu.inmite.apps.smsjizdenka.fragment.CitiesFragment.java
@Override public Loader<Object> onCreateLoader(int id, Bundle arg1) { if (id == Constants.LOADER_CITIES) { return new WrappedAsyncTaskLoader<Object>(c) { @Override/* w w w. j av a 2 s. c o m*/ public Object loadInBackground() { List<CitiesAdapter.Item> items = new ArrayList<CitiesAdapter.Item>(); CityManager cm = CityManager.get(c); // one closest LocationManager lm = (LocationManager) c.getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { City closest = cm.getClosest(c, location.getLatitude(), location.getLongitude()); if (closest != null) { items.add(new CitiesAdapter.Item(CitiesAdapter.Item.TYPE_HEADER, c.getString(R.string.cities_nearest))); items.add(new CitiesAdapter.Item(CitiesAdapter.Item.TYPE_CITY, closest.city)); } } // two last List<City> lastTwo = cm.getLastTwoUsed(c); if (lastTwo.size() > 0) { items.add(new CitiesAdapter.Item(CitiesAdapter.Item.TYPE_HEADER, c.getString(R.string.cities_recently_purchased))); items.add(new CitiesAdapter.Item(CitiesAdapter.Item.TYPE_CITY, lastTwo.get(0).city)); if (lastTwo.size() == 2) { items.add(new CitiesAdapter.Item(CitiesAdapter.Item.TYPE_CITY, lastTwo.get(1).city)); } } // all alphabetically List<City> all = cm.getUniqueCities(c); items.add(new CitiesAdapter.Item(CitiesAdapter.Item.TYPE_HEADER, c.getString(R.string.cities_all_tickets))); for (City city : all) { items.add(new CitiesAdapter.Item(CitiesAdapter.Item.TYPE_CITY, city.city)); } return items; } }; } return null; }
From source file:com.handlerexploit.news.fragments.WeatherFragment.java
@Override public void onResume() { super.onResume(); final Activity activity = getActivity(); if (activity != null) { threadPool.execute(new Runnable() { public void run() { final SharedPreferences sharedPreferences = activity.getSharedPreferences(".preferences", Context.MODE_PRIVATE); String location = sharedPreferences.getString("Location", null); if (location != null) { final WeatherInfo weatherInfo = WeatherProvider.getWeather(location); handler.post(new Runnable() { public void run() { render(weatherInfo); }//from w w w . ja v a 2s . c o m }); } else { Location lastKnownLocation = ((LocationManager) activity .getSystemService(Context.LOCATION_SERVICE)) .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (lastKnownLocation != null) { double longitude = lastKnownLocation.getLongitude(); double latitude = lastKnownLocation.getLatitude(); String url = "http://maps.google.com/maps/geo?ll=" + latitude + "," + longitude; try { String response = EntityUtils .toString(new DefaultHttpClient().execute(new HttpGet(url)).getEntity()); JSONObject addressDetails = new JSONObject(response).getJSONArray("Placemark") .getJSONObject(0).getJSONObject("AddressDetails"); JSONObject locality = addressDetails.getJSONObject("Country") .getJSONObject("AdministrativeArea").getJSONObject("Locality"); String raw; if (locality.get("PostalCode") == null) { raw = locality.getString("LocalityName"); } else { raw = locality.getJSONObject("PostalCode").getString("PostalCodeNumber"); } sharedPreferences.edit().putString("Location", raw).commit(); } catch (JSONException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { sharedPreferences.edit().putString("Location", "Miami").commit(); } final WeatherInfo weatherInfo = WeatherProvider.getWeather("Miami"); if (weatherInfo != null) { handler.post(new Runnable() { public void run() { render(weatherInfo); } }); } } } }); } }
From source file:com.initiativaromania.hartabanilorpublici.IRUserInterface.map.IRLocationListener.java
/** * Resume location setup after permissions have been granted *///from ww w . j av a2 s . co 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:com.laocuo.weather.presenter.impl.LocationPresenter.java
public String requestLocation() { String city = null;// www . j a v a2 s . c om if (!checkLocationPermission(mContext)) { // 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. requestLocationPermission((Activity) mContext); return null; } Location l = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (l != null) { L.d("getLastKnownLocation"); city = saveCityByLocation(l); } else { L.d("requestSingleUpdate"); if (!mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { mView.openLocation(); mLocationManager.requestSingleUpdate(LocationManager.PASSIVE_PROVIDER, mLocationListener, null); } else { mLocationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, mLocationListener, null); } } return city; }
From source file:com.fabernovel.alertevoirie.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dialog_shown = true;/* ww w.j ava2 s. c om*/ showDialog(DIALOG_PROGRESS); setContentView(R.layout.layout_home); // init buttons findViewById(R.id.Button_news).setOnClickListener(this); findViewById(R.id.Button_reports).setOnClickListener(this); findViewById(R.id.Button_new_incident).setOnClickListener(this); findViewById(R.id.Button_incidents).setOnClickListener(this); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); lastlocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); myHandler.postDelayed(removeUpdate, 30000); }