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:de.longri.cachebox3.AndroidPlatformConnector.java
@Override public void initialLocationReciver() { if (locationManager != null) { return;/*from w ww . j a v a2 s .c om*/ } locationListener = new AndroidLocationListener(); // GPS // Get the location manager locationManager = (LocationManager) this.application.getSystemService(Context.LOCATION_SERVICE); final int updateTime = 500; //500ms //TODO get gps updateTime from settings // int updateTime = Config.gpsUpdateTime.getValue(); // // Config.gpsUpdateTime.addChangedEventListener(new IChanged() { // // @Override // public void isChanged() { // int updateTime = Config.gpsUpdateTime.getValue(); // locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, 1, this); // } // }); application.runOnUiThread(new Runnable() { @Override public void run() { try { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateTime, 1, locationListener); if (ActivityCompat.checkSelfPermission(AndroidPlatformConnector.this.application, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(AndroidPlatformConnector.this.application, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 300, locationListener); locationManager.addNmeaListener(locationListener); locationManager.addGpsStatusListener(locationListener); } catch (Exception e) { log.error("main.initialLocationManager()", e); e.printStackTrace(); } } }); }
From source file:com.itsherpa.andg.ui.LocationFragment.java
@Override public void onStart() { super.onStart(); mGoogleApiClient.connect();/* ww w.jav a2 s . c o m*/ mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0F, oldLocationListener); }
From source file:ti.modules.titanium.geolocation.TiLocation.java
public boolean getLocationServicesEnabled() { List<String> providerNames = locationManager.getProviders(true); if (Log.isDebugModeEnabled()) { Log.i(TAG, "Enabled location provider count: " + providerNames.size()); for (String providerName : providerNames) { Log.i(TAG, providerName + " service available"); }/* www. j av a2 s. c o m*/ } // don't count the passive provider for (String name : providerNames) { if (name.equals(LocationManager.NETWORK_PROVIDER) || name.equals(LocationManager.GPS_PROVIDER)) { return true; } } return false; }
From source file:com.example.scandevice.GeofenceTransitionsIntentService.java
/** * Handles incoming intents./*from w ww .j a v a2 s . co m*/ * @param intent sent by Location Services. This Intent is provided to Location * Services (inside a PendingIntent) when addGeofences() is called. */ @Override protected void onHandleIntent(Intent intent) { initializeLocationManager(); try { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE, mLocationListeners[0]); } catch (java.lang.SecurityException ex) { Log.i(TAG, "fail to request location update, ignore", ex); } catch (IllegalArgumentException ex) { Log.d(TAG, "network provider does not exist, " + ex.getMessage()); } GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); if (geofencingEvent.hasError()) { Log.w(TAG, "hasError"); return; } // Get the transition type. int geofenceTransition = geofencingEvent.getGeofenceTransition(); // Test that the reported transition was of interest. if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) { // Get the geofences that were triggered. A single event can trigger multiple geofences. List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Get the transition details as a String. String geofenceTransitionDetails = getGeofenceTransitionDetails(this, geofenceTransition, triggeringGeofences); // Send notification and log the transition details. sendNotification(geofenceTransitionDetails); Log.i(TAG, geofenceTransitionDetails); } else { // Log the error. Log.e(TAG, getString(R.string.geofence_transition_invalid_type, geofenceTransition)); } }
From source file:com.clevertrail.mobile.findtrail.Activity_FindTrail_ByLocation.java
public void onResume() { super.onResume(); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); }
From source file:com.nextgis.mobile.forms.CameraFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setRetainInstance(true);//from w w w .ja v a 2 s.com View view = inflater.inflate(R.layout.camfragment, container, false); Button button = (Button) view.findViewById(R.id.insert_take_photo); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onCapturePhoto(); } }); ListView photoList = (ListView) view.findViewById(R.id.poi_photos_list); adapter = new SimpleAdapter(view.getContext(), listItems, R.layout.row, new String[] { IMG_NAME, IMG_ROT, }, new int[] { R.id.image_name, R.id.image_rotation }); photoList.setAdapter(adapter); final LocationManager locationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); if (currentLocation == null) { currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (currentLocation == null) { currentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } } long now = System.currentTimeMillis(); declination = CompassFragment.getDeclination(currentLocation, now); sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); return view; }
From source file:com.vonglasow.michael.satstat.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); // Show the Up button in the action bar. ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); // Display the fragment as the main content. getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit(); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // some logic to use the pre-1.7 setting KEY_PREF_UPDATE_WIFI as a // fallback if KEY_PREF_UPDATE_NETWORKS is not set if (!mSharedPreferences.contains(KEY_PREF_UPDATE_NETWORKS)) { Set<String> fallbackUpdateNetworks = new HashSet<String>(); if (mSharedPreferences.getBoolean(KEY_PREF_UPDATE_WIFI, false)) { fallbackUpdateNetworks.add(KEY_PREF_UPDATE_NETWORKS_WIFI); }// w w w .j a v a 2 s . co m SharedPreferences.Editor spEditor = mSharedPreferences.edit(); spEditor.putStringSet(KEY_PREF_UPDATE_NETWORKS, fallbackUpdateNetworks); spEditor.commit(); } // by default, show GPS and network location in map if (!mSharedPreferences.contains(KEY_PREF_LOC_PROV)) { Set<String> defaultLocProvs = new HashSet<String>( Arrays.asList(new String[] { LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER })); SharedPreferences.Editor spEditor = mSharedPreferences.edit(); spEditor.putStringSet(KEY_PREF_LOC_PROV, defaultLocProvs); spEditor.commit(); } }
From source file:com.jmstudios.redmoon.preference.LocationPreference.java
public void searchLocation(boolean explicitRequest) { if (mIsSearchingLocation) mIsSearchExplicit = explicitRequest || mIsSearchExplicit; else/*from www .j a v a 2s.c om*/ mIsSearchExplicit = explicitRequest; if (!mIsSearchingLocation) { if (DEBUG) Log.i(TAG, explicitRequest ? "Searching location on explicit request" : "Searching location automatically"); mIsSearchingLocation = true; LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationListener listener = new LocationUpdateListener(mContext, this); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener); } else { handleLocationSearchFailed(); } } if (mIsSearchExplicit && mIsSearchingLocation) { setSummary(mContext.getString(R.string.searching_location)); } }
From source file:com.tagaugmentedreality.utilties.Utilities.java
public static boolean locationProviderStatus(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { return true; } // end if/*from w w w.j a va 2 s . com*/ else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { return true; } // end if else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { return true; } // end else if else { return false; } // end else }
From source file:at.ac.tuwien.caa.docscan.camera.LocationHandler.java
private LocationHandler(Context context) { mContext = context;/*from www .j a v a 2s . 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(); } }