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:activities.GatewayActivity.java
@Override public void locationMode(boolean on) { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (on) {//from w w w . j a va2s . co m if (!gpsEnabled || !networkEnabled) { new LocationDialog().show(getSupportFragmentManager(), "locationdialog"); configFragment.updateLocationView(false); sApp.isLocationOn = false; } else { if (!sApp.locationService.isRunning()) sApp.locationService.start(); sApp.isLocationOn = true; showToast(getString(R.string.location_enabled)); } } else { if (sApp.locationService.isRunning()) sApp.locationService.stop(); showToast(getString(R.string.toast_stopped_location_service)); sApp.isLocationOn = false; } configFragment.updateLocationView(sApp.isLocationOn); }
From source file:com.nextgis.firereporter.GetFiresService.java
protected void GetUserData(boolean bShowProgress) { Location currentLocation = null; String sLat = null, sLon = null; if (mLocManager != null) { currentLocation = mLocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (currentLocation == null) { currentLocation = mLocManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); }/*from www . ja v a2s. co m*/ if (currentLocation == null) { SendError(getString(R.string.noLocation)); return; } else { sLat = Double.toString(currentLocation.getLatitude()); sLon = Double.toString(currentLocation.getLongitude()); } } SharedPreferences prefs = getSharedPreferences(MainActivity.PREFERENCES, MODE_PRIVATE | MODE_MULTI_PROCESS); String sURL = prefs.getString(SettingsActivity.KEY_PREF_SRV_USER, getResources().getString(R.string.stDefaultServer)); String sLogin = prefs.getString(SettingsActivity.KEY_PREF_SRV_USER_USER, "firereporter"); String sPass = prefs.getString(SettingsActivity.KEY_PREF_SRV_USER_PASS, "8QdA4"); int nDayInterval = prefs.getInt(SettingsActivity.KEY_PREF_SEARCH_DAY_INTERVAL + "_int", 5); int fetchRows = prefs.getInt(SettingsActivity.KEY_PREF_ROW_COUNT + "_int", 15); int searchRadius = prefs.getInt(SettingsActivity.KEY_PREF_FIRE_SEARCH_RADIUS + "_int", 5) * 1000;//meters boolean searchByDate = prefs.getBoolean("search_current_date", false); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); long diff = 86400000L * nDayInterval;//1000 * 60 * 60 * 24 * 5;// 5 days date.setTime(date.getTime() - diff); String dt = dateFormat.format(date); String sFullURL = sURL + "?function=get_rows_user&user=" + sLogin + "&pass=" + sPass + "&limit=" + fetchRows + "&radius=" + searchRadius;// if (searchByDate) { sFullURL += "&date=" + dt; } if (sLat.length() > 0 && sLon.length() > 0) { sFullURL += "&lat=" + sLat + "&lon=" + sLon; } //SELECT * FROM (SELECT id, report_date, latitude, longitude, round(ST_Distance_Sphere(ST_PointFromText('POINT(37.506247479468584 55.536129316315055)', 4326), fires.geom)) AS dist FROM fires WHERE ST_Intersects(fires.geom, ST_GeomFromText('POLYGON((32.5062474795 60.5361293163, 42.5062474795 60.5361293163, 42.5062474795 50.5361293163, 32.5062474795 50.5361293163, 32.5062474795 60.5361293163))', 4326) ) AND CAST(report_date as date) >= '2013-09-27')t WHERE dist <= 5000 LIMIT 15 //String sRemoteData = "http://gis-lab.info/data/zp-gis/soft/fires.php?function=get_rows_nasa&user=fire_usr&pass=J59DY&limit=5"; new HttpGetter(this, 1, getResources().getString(R.string.stDownLoading), mFillDataHandler, bShowProgress) .execute(sFullURL); }
From source file:br.com.rescue_bots_android.bluetooth.MainActivity.java
public void initGPSListener() { // create class object gps = new GPSTrackerImplementation(this); // check if GPS enabled if (gps.canGetLocation()) { String locationText = getLocationText(gps.getLocation()); if (locationText != null) { Log.i("INFO", locationText); } else {/*from www .ja v a 2s. c o m*/ Log.i("INFO", "Sem coordenada"); } } else { // can't get location // GPS or Network is not enabled // Ask user to enable GPS/network in settings gps.showSettingsAlert(); } if (mBtnClearInput.getText().toString().equalsIgnoreCase(LocationManager.GPS_PROVIDER)) { mBtnClearInput.setText(LocationManager.NETWORK_PROVIDER); gps.setProvider(LocationManager.NETWORK_PROVIDER); } else { mBtnClearInput.setText(LocationManager.GPS_PROVIDER); gps.setProvider(LocationManager.GPS_PROVIDER); } }
From source file:org.unchiujar.umbra2.services.LocationService.java
/** * Turns on fast GPS updates when the application is in foreground and tries to display the last * known location.//from w ww. j a va 2 s .c o m */ private void setOnScreeState() { mOnScreen = true; stopBackoff(); Location network = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); Location gps = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); // Location passive = // mLocationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); // Location toSend = (gps != null) ? gps : (network != null) ? network // : (passive != null) ? passive : null; Location toSend = (gps != null) ? gps : (network != null) ? network : null; if (toSend != null) { sendLocation(toSend); } // register fast location listener mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, SCREEN_ON_UPDATE_INTERVAL, SCREEN_ON_UPDATE_DISTANCE, mFine); }
From source file:net.evecom.androidecssp.activity.event.EventInfoActivity.java
/** * /*ww w . ja v a 2s.co m*/ * * * @author Mars zhang * @created 2015-12-1 11:45:22 */ private void requestLocationUpdate() { // mMyLocation = new MyOverlay(EventInfoActivity.this, null); // locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { // toast("", 0); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, mMyLocation); } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, mMyLocation); // toast("", 0); } else { // toast("", 0); } }
From source file:com.hufeiya.SignIn.activity.QuizActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case REQUEST_CODE_FOR_POSITON: if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, this); } else {/*from ww w . java2 s . c o m*/ // TODO permission denied, boo! Disable the // functionality that depends on this permission. } break; case REQUEST_CAMARA_PERMISSION: if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { setStateBeforeCameraPreview(); startCameraPreview(); } } }
From source file:library.artaris.cn.library.utils.SystemUtils.java
/** * GPS?// ww w . ja v a 2s . c o m * <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> */ public static boolean isGpsEnabled(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // GPS????24???? boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); // WLAN(3G/2G)?AGPSGPS???? boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); return gps || network; }
From source file:org.noise_planet.noisecapture.MeasurementService.java
private void stopNetworkLocation() { if (networkLocationListener == null || networkLocationManager == null) { return;/*w ww .j a v a2 s.co m*/ } networkLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && networkLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { networkLocationManager.removeUpdates(networkLocationListener); } }
From source file:org.phillyopen.mytracks.cyclephilly.MainInput.java
/** Called when the activity is first created. */ @Override/*from w w w .j a v a2 s . com*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Firebase.setAndroidContext(this); final Firebase ref = new Firebase("https://cyclephilly.firebaseio.com"); final Firebase phlref = new Firebase("https://phl.firebaseio.com"); // Let's handle some launcher lifecycle issues: // If we're recording or saving right now, jump to the existing activity. // (This handles user who hit BACK button while recording) setContentView(R.layout.main); weatherFont = Typeface.createFromAsset(getAssets(), "cyclephilly.ttf"); weatherText = (TextView) findViewById(R.id.weatherView); weatherText.setTypeface(weatherFont); weatherText.setText(R.string.cloudy); Intent rService = new Intent(this, RecordingService.class); ServiceConnection sc = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { } public void onServiceConnected(ComponentName name, IBinder service) { IRecordService rs = (IRecordService) service; int state = rs.getState(); if (state > RecordingService.STATE_IDLE) { if (state == RecordingService.STATE_FULL) { startActivity(new Intent(MainInput.this, SaveTrip.class)); } else { // RECORDING OR PAUSED: startActivity(new Intent(MainInput.this, RecordingActivity.class)); } MainInput.this.finish(); } else { // Idle. First run? Switch to user prefs screen if there are no prefs stored yet SharedPreferences settings = getSharedPreferences("PREFS", 0); String anon = settings.getString("" + PREF_ANONID, "NADA"); if (settings.getAll().isEmpty()) { showWelcomeDialog(); } else if (anon == "NADA") { showWelcomeDialog(); } // Not first run - set up the list view of saved trips ListView listSavedTrips = (ListView) findViewById(R.id.ListSavedTrips); populateList(listSavedTrips); } MainInput.this.unbindService(this); // race? this says we no longer care } }; // This needs to block until the onServiceConnected (above) completes. // Thus, we can check the recording status before continuing on. bindService(rService, sc, Context.BIND_AUTO_CREATE); // And set up the record button final Button startButton = (Button) findViewById(R.id.ButtonStart); final Intent i = new Intent(this, RecordingActivity.class); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.US); SharedPreferences settings = getSharedPreferences("PREFS", 0); final String anon = settings.getString("" + PREF_ANONID, "NADA"); Firebase weatherRef = new Firebase("https://publicdata-weather.firebaseio.com/philadelphia"); Firebase tempRef = new Firebase("https://publicdata-weather.firebaseio.com/philadelphia/currently"); tempRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Object val = dataSnapshot.getValue(); String cardinal = null; TextView tempState = (TextView) findViewById(R.id.temperatureView); // TextView liveTemp = (TextView) findViewById(R.id.warning); String apparentTemp = ((Map) val).get("apparentTemperature").toString(); String windSpeed = ((Map) val).get("windSpeed").toString(); Double windValue = (Double) ((Map) val).get("windSpeed"); Long windBearing = (Long) ((Map) val).get("windBearing"); // liveTemp.setText(" "+apparentTemp.toString()+DEGREE); WindDirection[] windDirections = WindDirection.values(); for (int i = 0; i < windDirections.length; i++) { if (windDirections[i].startDegree < windBearing && windDirections[i].endDegree > windBearing) { //Get Cardinal direction cardinal = windDirections[i].cardinal; } } if (windValue > 4) { tempState.setTextColor(0xFFDC143C); tempState.setText("winds " + cardinal + " at " + windSpeed + " mph. Ride with caution."); } else { tempState.setTextColor(0xFFFFFFFF); tempState.setText("winds " + cardinal + " at " + windSpeed + " mph."); } } @Override public void onCancelled(FirebaseError firebaseError) { } }); connectedListener = ref.getRoot().child(".info/connected").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { boolean connected = (Boolean) dataSnapshot.getValue(); if (connected) { System.out.println("connected " + dataSnapshot.toString()); Firebase cycleRef = new Firebase(FIREBASE_REF + "/" + anon + "/connections"); // cycleRef.setValue(Boolean.TRUE); // cycleRef.onDisconnect().removeValue(); } else { System.out.println("disconnected"); } } @Override public void onCancelled(FirebaseError error) { // No-op } }); weatherRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { Object value = snapshot.getValue(); Object hourly = ((Map) value).get("currently"); String alert = ((Map) hourly).get("summary").toString(); // TextView weatherAlert = (TextView) findViewById(R.id.weatherAlert); // weatherAlert.setText(alert); } @Override public void onCancelled(FirebaseError firebaseError) { } }); // Acquire a reference to the system Location Manager // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. mySpot = new LatLng(location.getLatitude(), location.getLongitude()); makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; nearbyStations = (RecyclerView) findViewById(R.id.nearbyStationList); nearbyStations.setLayoutManager(new LinearLayoutManager(getApplicationContext())); //Listener for Indego Changes indegoRef = new Firebase("https://phl.firebaseio.com/indego/kiosks"); indegoRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { //Updates! Add them to indego data list indegoDataList = dataSnapshot; } @Override public void onCancelled(FirebaseError firebaseError) { } }); // Register the listener with the Location Manager to receive location updates indegoGeofireRef = new Firebase("https://phl.firebaseio.com/indego/_geofire"); GeoFire geoFire = new GeoFire(indegoGeofireRef); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); mySpot = myCurrentLocation(); indegoList = new ArrayList<IndegoStation>(); System.out.println("lo: " + mySpot.toString()); GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(mySpot.longitude, mySpot.latitude), 0.5); geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() { @Override public void onKeyEntered(String key, GeoLocation location) { System.out.println(String.format("Key %s entered the search area at [%f,%f]", key, location.latitude, location.longitude)); //Create Indego Station object. To-do: check if object exists IndegoStation station = new IndegoStation(); station.kioskId = key; station.location = location; if (indegoDataList != null) { //get latest info from list station.name = (String) indegoDataList.child(key).child("properties").child("name").getValue(); } System.out.println(station.name); indegoList.add(station); //To-do: Add indego station info to RideIndegoAdapter } @Override public void onKeyExited(String key) { } @Override public void onKeyMoved(String key, GeoLocation location) { } @Override public void onGeoQueryReady() { System.out.println("GEO READY :" + indegoList.toString()); indegoAdapter = new RideIndegoAdapter(getApplicationContext(), indegoList); nearbyStations.setAdapter(indegoAdapter); } @Override public void onGeoQueryError(FirebaseError error) { System.out.println("GEO error"); } }); startButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Before we go to record, check GPS status final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps(); } else { startActivity(i); MainInput.this.finish(); } } }); toolbar = (Toolbar) findViewById(R.id.dashboard_bar); toolbar.setTitle("Cycle Philly"); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(true); }
From source file:net.e_fas.oss.tabijiman.MapsActivity.java
@Override protected void onResume() { if (mLocationManager != null) { e_print("onResume_mLocationManager >> NotNull"); providers = mLocationManager.getProviders(true); } else {/* w w w . jav a2 s . c om*/ e_print("onResume_mLocationManager >> null"); } super.onResume(); e_print("onResume"); Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); e_print("last_location >> " + location); }