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:org.y20k.trackbook.TrackerService.java
private void startFindingLocation() { // register location listeners and request updates List locationProviders = mLocationManager.getAllProviders(); if (locationProviders.contains(LocationManager.GPS_PROVIDER)) { mGPSListener = createLocationListener(); mTrackerServiceRunning = true;//from w ww . j a v a 2 s .com } if (locationProviders.contains(LocationManager.NETWORK_PROVIDER)) { mNetworkListener = createLocationListener(); mTrackerServiceRunning = true; } LocationHelper.registerLocationListeners(mLocationManager, mGPSListener, mNetworkListener); }
From source file:com.forrestguice.suntimeswidget.getfix.GetFixHelper.java
public static boolean isNetProviderEnabled(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); }
From source file:com.hufeiya.SignIn.activity.QuizActivity.java
private void getLocation() { locationManager = (LocationManager) MyApplication.getContext().getSystemService(Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(MyApplication.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(MyApplication.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(QuizActivity.this, "??? ( > c < ) ", Toast.LENGTH_SHORT).show(); String locationPermissions[] = { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION }; int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= 23) { requestPermissions(locationPermissions, REQUEST_CODE_FOR_POSITON); }/*ww w .j a v a 2s. c o m*/ return; } locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, this); }
From source file:com.example.sans.myapplication.Utility.MainActivity.java
protected void startLocationUpdates() { lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll); }
From source file:org.noise_planet.noisecapture.MeasurementService.java
private void initNetworkLocation() { if (networkLocationListener == null) { networkLocationListener = new CommonLocationListener(this, LISTENER.NETWORK); }//from ww w .ja va 2 s .com networkLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && networkLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { networkLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, minTimeDelay, 0, networkLocationListener); } }
From source file:com.bangz.smartmute.services.LocationMuteService.java
private boolean addGeofences(List<Geofence> geofences) { ConnectionResult connresult = mGoogleApiClient.blockingConnect(); if (connresult.isSuccess() == false) { LogUtils.LOGE(TAG, "GoogleApiClient.blockingConnect failed! message: " + connresult.toString()); return false; }//from w w w . j a v a2s. com GeofencingRequest gR = new GeofencingRequest.Builder().addGeofences(geofences) .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER | GeofencingRequest.INITIAL_TRIGGER_DWELL | GeofencingRequest.INITIAL_TRIGGER_EXIT) .build(); PendingIntent pi = getGeofencesPendingIntent(this); Status rs = LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, gR, pi).await(); boolean bret = false; if (rs.isSuccess()) { LogUtils.LOGD(TAG, "Add Geofence successful."); PrefUtils.Geofencing(this, true); ReceUtils.enableReceiver(this, LocationProviderChangedReceiver.class, false); bret = true; } else { int errcode = rs.getStatusCode(); bret = false; LogUtils.LOGD(TAG, "Add Geofence failed! errorcode = " + errcode + "Message:" + rs.getStatusMessage()); if (errcode == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) { LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER) || lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { LogUtils.LOGD(TAG, "GPS or Network Provider is enabled. " + "Notification User to try add again late?"); } else { ReceUtils.enableReceiver(this, LocationProviderChangedReceiver.class, true); } NotificationUserFailed(); } } mGoogleApiClient.disconnect(); return bret; }
From source file:com.davidmascharka.lips.MainActivity.java
@Override public void onResume() { super.onResume(); // Set building textview to the building the user has selected TextView buildingText = (TextView) findViewById(R.id.text_building); buildingText.setText("Building: " + building); // Set room size textview to the room size the user has selected TextView roomSizeText = (TextView) findViewById(R.id.text_room_size); roomSizeText.setText("Room size: " + roomWidth + " x " + roomLength); // Set grid options GridView grid = (GridView) findViewById(R.id.gridView); grid.setGridSize(roomWidth, roomLength); grid.setDisplayMap(displayMap);/*ww w .j av a 2s .c o m*/ // Register to get sensor updates from all the available sensors sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensorList) { sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_FASTEST); } // Enable wifi if it is not if (!wifiManager.isWifiEnabled()) { Toast.makeText(this, "WiFi not enabled. Enabling...", Toast.LENGTH_SHORT).show(); wifiManager.setWifiEnabled(true); } // Request location updates from gps and the network //@author Mahesh Gaya added permission if-statment if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.CHANGE_WIFI_STATE) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Log.i(TAG, "Permissions have NOT been granted. Requesting permissions."); requestMyPermissions(); } else { Log.i(TAG, "Permissions have already been granted. Getting location from GPS and Network"); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } registerReceiver(receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); }
From source file:org.odk.collect.android.activities.GeoPointMapActivity.java
private void upMyLocationOverlayLayers() { // make sure we have a good location provider before continuing location_count_num = 0;/* ww w . j av a 2s . co m*/ List<String> providers = mLocationManager.getProviders(true); for (String provider : providers) { if (provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER)) { mGPSOn = true; mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); location_count_found_limit = 0; } else if (provider.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)) { // Only if GPS Providor is not avaibe use network location. bug (well know // android bug) http://stackoverflow // .com/questions/6719207/locationmanager-returns-old-cached-wifi-location-with // -current-timestamp mNetworkOn = true; location_count_found_limit = 1; // increase count due to network location bug (well know android bug) mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } } // mShowLocation.setClickable(mMarker != null); if (!mGPSOn && !mNetworkOn) { showGPSDisabledAlertToUser(); } else { overlayMyLocationLayers(); } }
From source file:com.landenlabs.all_devtool.GpsFragment.java
@SuppressWarnings("deprecation") @Override/* w ww .j a va2s . co m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); View rootView = inflater.inflate(R.layout.gps_tab, container, false); m_statusIcon = Ui.viewById(rootView, R.id.gpsStatus); m_statusIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } }); Ui.viewById(rootView, R.id.gps_clear).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { clearList(); } }); m_list.clear(); // ---- Get UI components ---- for (int idx = 0; idx != s_maxRows; idx++) m_list.add(null); m_list.set(s_providersRow, new GpsInfo(new GpsItem("Providers"))); m_list.set(s_lastUpdateRow, new GpsInfo(new GpsItem("Last Update"))); m_list.set(s_detailRow, new GpsInfo(new GpsItem("Detail History"))); m_listView = Ui.viewById(rootView, R.id.gpsListView); final GpsArrayAdapter adapter = new GpsArrayAdapter(this.getActivity()); m_listView.setAdapter(adapter); // ---- Setup GPS ---- m_locMgr = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); m_gpsTv = Ui.viewById(rootView, R.id.gps); if (isGooglePlayServicesAvailable()) { m_locationRequest = new LocationRequest(); m_locationRequest.setInterval(GPS_INTERVAL); m_locationRequest.setFastestInterval(GPS_FASTEST_INTERVAL); // Priority needs to match permissions. // Use LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY with // <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> // Use LocationRequest.PRIORITY_HIGH_ACCURACY with // <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> m_locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); m_googleApiClient = new GoogleApiClient.Builder(this.getActivity()).addApi(LocationServices.API) .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build(); m_gpsTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { m_gpsMonitor = !m_gpsMonitor; view.setSelected(m_gpsMonitor); addMsgToDetailRow(s_colorMsg, m_gpsMonitor ? "Start Monitor" : "Stop Monitor"); showProviders(); } }); } else { m_gpsTv.setText("Need Google Play Service"); } if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { m_locMgr.addGpsStatusListener(this); } /* http://stackoverflow.com/questions/11398732/how-do-i-receive-the-system-broadcast-when-gps-status-has-changed <uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <receiver android:name=".GpsReceiver"> <intent-filter> <action android:name="android.location.GPS_ENABLED_CHANGE" /> <action android:name="android.location.PROVIDERS_CHANGED" /> </intent-filter> </receiver> */ // GpsReceiver m_gpsReceiver = new GpsReceiver(); m_intentFilter.addAction(GpsReceiver.GPS_ENABLED_CHANGE_ACTION); if (Build.VERSION.SDK_INT >= 19) { m_intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION); } m_intentFilter.addAction(GpsReceiver.GPS_FIX_CHANGE_ACTION); m_intentFilter.addAction(LocationManager.PROVIDERS_CHANGED_ACTION); showProviders(); // TODO - get available providers getCheckBox(rootView, R.id.gpsFuseCb, FUSED_PROVIDER); getCheckBox(rootView, R.id.gpsGPSCb, LocationManager.GPS_PROVIDER); getCheckBox(rootView, R.id.gpsNetwkCb, LocationManager.NETWORK_PROVIDER); getCheckBox(rootView, R.id.gpsLowPwrCb, LocationManager.PASSIVE_PROVIDER); getCheckBox(rootView, R.id.gpsStatusCb, STATUS_CB); for (CheckBox cb : m_providersCb.values()) { cb.setOnClickListener(this); } initLastUpdate(); // Expand All for (int idx = 0; idx != s_maxRows; idx++) m_listView.expandGroup(idx); return rootView; }
From source file:com.warp10.app.LocationService.java
/** * End of service, unregistered GPS or Network providers *//*www.jav a 2s . c o m*/ public void onDestroy() { if (isRunning) { if (null != locationManager) { locationListener.onProviderDisabled(LocationManager.NETWORK_PROVIDER); locationManager.removeUpdates(locationListener); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, 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; } locationListener.onProviderDisabled(LocationManager.GPS_PROVIDER); locationManager = null; //Log.d("LOCATION", "Detroyed"); } //stopSelf(); //Log.d("LOC", "STOP service location"); isRunning = false; } }