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.net.rmopenmenu.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.fragment_tabs_pager); mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup();/*from www .j a va 2 s .c om*/ mViewPager = (ViewPager) findViewById(R.id.pager); mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Bundle b1 = new Bundle(); b1.putBoolean("menu", true); Bundle b2 = new Bundle(); b2.putBoolean("menu", false); mTabsAdapter.addTab(mTabHost.newTabSpec("menu").setIndicator("Menu"), MenuFragment.class, b1); mTabsAdapter.addTab(mTabHost.newTabSpec("restaurant").setIndicator("Restaurant"), MenuFragment.class, b2); if (savedInstanceState != null) { mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); } // Acquire a reference to the system Location Manager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(Location location) { SharedPreferences.Editor editor = prefs.edit(); editor.putInt("lat", (int) (location.getLatitude() * 1000000)); editor.putInt("lon", (int) (location.getLongitude() * 1000000)); editor.commit(); } }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); }
From source file:nu.shout.shout.chat.ChatService.java
@Override public void onCreate() { Log.v(TAG, "Creating ChatService"); this.mentionNoti = new ChatNotifier(this, Notifications.MENTIONED.ordinal()); this.listeners.add(this.mentionNoti); this.irc = new IRCConnection(); IRCListenerAdapter adapter = new IRCListenerAdapter(this); this.irc.getListenerManager().addListener(adapter); this.bf = new BuildingFetcher(); this.settings = PreferenceManager.getDefaultSharedPreferences(this); this.lm = (LocationManager) getSystemService(LOCATION_SERVICE); this.lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, TIME_BETWEEN_LOC, DIST_BETWEEN_LOC, this); // Pick last known location this.onLocationChanged(this.lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)); }
From source file:org.wso2.emm.agent.services.location.impl.LocationServiceImpl.java
/** * In this method, it gets the latest location updates from gps/ network. */// w ww. j a v a 2 s. c o m private void setLocation() { if (locationManager != null) { try { if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); if (locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { Preference.putString(context, context.getResources().getString(R.string.shared_pref_location), new Gson().toJson(location)); } } if (location == null) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); if (locationManager != null) { location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { Preference.putString(context, context.getResources().getString(R.string.shared_pref_location), new Gson().toJson(location)); } } } } catch (RuntimeException e) { Log.e(TAG, "No network/GPS Switched off.", e); } } }
From source file:com.hoccer.api.android.LinccLocationManager.java
public void activate() { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this); if (mNetworkProviderAvailable) { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, this); }/*from ww w . jav a 2 s . c om*/ }
From source file:com.vrjco.v.demo.MainActivity.java
private void startLogging(boolean check) { if (check) {/*from w w w .j ava 2 s. co m*/ //checking if gps and network is ON. gpsok = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); networkok = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, "LOCATION PROVIDER PERMISSIONS NOT GRANTED", Toast.LENGTH_LONG).show(); return; } checking = true; //checking every 100 miliSec and minDistance change 0 lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, logLocationListener); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, logLocationListener); if (gpsok && networkok) { Toast.makeText(this, "GPS and NETWORK PROVIDER Found!!", Toast.LENGTH_SHORT).show(); location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { lat = location.getLatitude(); longi = location.getLongitude(); tvlat.setText(Double.toString(lat)); tvlongi.setText(Double.toString(longi)); } } else { Toast.makeText(this, "LOCATION PROVIDER NOT AVAILABLE", Toast.LENGTH_LONG).show(); } } else { lm.removeUpdates(logLocationListener); checking = false; } }
From source file:com.example.demo_dv_fuse.MapScreen.java
/** * @see android.app.Activity#onCreate(android.os.Bundle) *//*from w ww . j a v a2 s .c o m*/ @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_screen); this.map = ((MapFragment) getFragmentManager().findFragmentById(R.id.mapView)).getMap(); this.map.setMapType(GoogleMap.MAP_TYPE_NORMAL); final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext()); if (status == ConnectionResult.SUCCESS) { // Google Play Services is available // Enabling MyLocation Layer of Google Map this.map.setMyLocationEnabled(true); // Getting LocationManager object from System Service LOCATION_SERVICE final LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); // Creating a criteria object to retrieve provider final Criteria criteria = new Criteria(); // Getting the name of the best provider final String provider = locationManager.getBestProvider(criteria, true); // Getting Current Location final Location location = locationManager.getLastKnownLocation(provider); if (location != null) { onLocationChanged(location); // } else { // final String coordinates[] = {"1.352566007", "103.78921587"}; // final double lat = Double.parseDouble(coordinates[0]); // final double lng = Double.parseDouble(coordinates[1]); // // // Creating a LatLng object for the current location // LatLng latLng = new LatLng(lat, lng); // // // Showing the current location in Google Map // this.map.moveCamera(CameraUpdateFactory.newLatLng(latLng)); // this.map.animateCamera(CameraUpdateFactory.zoomTo(15)); } boolean enabledGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean enabledWiFi = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); // Check if enabled and if not send user to the GSP settings // Better solution would be to display a dialog and suggesting to // go to the settings if (!enabledGPS || !enabledWiFi) { Toast.makeText(this, "GPS signal not found", Toast.LENGTH_LONG).show(); Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } locationManager.requestLocationUpdates(provider, 20000, 0, this); } else { // Google Play Services are not available final int requestCode = 10; final Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode); dialog.show(); } }
From source file:com.platform.GeoLocationManager.java
public void getOneTimeGeoLocation(Continuation cont, Request req) { this.continuation = cont; this.baseRequest = req; final MainActivity app = MainActivity.app; if (app == null) return;//from w ww .j a v a2 s . co m locationManager = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE); if (locationManager == null) { Log.e(TAG, "getOneTimeGeoLocation: locationManager is null!"); return; } app.runOnUiThread(new Runnable() { @Override public void run() { if (ActivityCompat.checkSelfPermission(app, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(app, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { RuntimeException ex = new RuntimeException("getOneTimeGeoLocation, can't happen"); Log.e(TAG, "run: getOneTimeGeoLocation, can't happen"); FirebaseCrash.report(ex); return; } locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); } }); }
From source file:com.collectme.cordova.diagnostic.Diagnostic.java
public boolean isNetworkEnabled() { boolean result = isLocationProviderEnabled(LocationManager.NETWORK_PROVIDER); Log.d(TAG, "Network enabled: " + result); return result; }
From source file:com.jmstudios.redmoon.receiver.AutomaticFilterChangeReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (DEBUG)/*from ww w .j av a2 s . c om*/ Log.i(TAG, "Alarm received"); FilterCommandSender commandSender = new FilterCommandSender(context); FilterCommandFactory commandFactory = new FilterCommandFactory(context); Intent onCommand = commandFactory.createCommand(ScreenFilterService.COMMAND_ON); Intent pauseCommand = commandFactory.createCommand(ScreenFilterService.COMMAND_PAUSE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); SettingsModel settingsModel = new SettingsModel(context.getResources(), sharedPreferences); boolean turnOn = intent.getData().toString().equals("turnOnIntent"); if (turnOn) { commandSender.send(onCommand); cancelTurnOnAlarm(context); scheduleNextOnCommand(context); } else { commandSender.send(pauseCommand); cancelPauseAlarm(context); scheduleNextPauseCommand(context); // We want to dismiss the notification if the filter is paused // automatically. // However, the filter fades out and the notification is only // refreshed when this animation has been completed. To make sure // that the new notification is removed we create a new runnable to // be excecuted 100 ms after the filter has faded out. Handler handler = new Handler(); DismissNotificationRunnable runnable = new DismissNotificationRunnable(context); handler.postDelayed(runnable, ScreenFilterPresenter.FADE_DURATION_MS + 100); } if (settingsModel.getAutomaticFilterMode().equals("sun")) { // Update times for the next time (fails silently) LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationListener listener = new LocationUpdateListener(context); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener); } } }
From source file:com.djit.mixfader.sample.BaseActivity.java
/** * Check if the user needs to enable the location. * <p/>/*from www .ja va2 s .co m*/ * Since Android Marshmallow, the location is required to scan for bluetooth devices. * * @return Return true is the location need to be enable, false otherwise. */ private static boolean needToEnableLocation(final Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return false; } else { final LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE); return !locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); } }