List of usage examples for android.location LocationManager isProviderEnabled
public boolean isProviderEnabled(String provider)
From source file:com.platform.middlewares.plugins.GeoLocationPlugin.java
private JSONObject getAuthorizationError(Context app) { String error = null;/*ww w . j a v a 2 s.co m*/ LocationManager lm = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE); boolean gps_enabled = false; boolean network_enabled = false; try { gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ignored) { } try { network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } catch (Exception ignored) { } if (!gps_enabled && !network_enabled) { error = "Location services are disabled"; } int permissionCheck = ContextCompat.checkSelfPermission(app, Manifest.permission.ACCESS_FINE_LOCATION); if (permissionCheck != PackageManager.PERMISSION_GRANTED) { error = "Location services are not authorized"; } if (error != null) { JSONObject obj = new JSONObject(); try { obj.put("error", error); } catch (JSONException e) { e.printStackTrace(); } return obj; } else { return null; } }
From source file:com.example.leandromaguna.myapp.Presentation.PlacesMap.PlacesMapActivity.java
/** * Enables the My Location layer if the fine location permission has been granted. *//* ww w .j a v a 2 s . co m*/ private void enableMyLocation() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Permission to access the location is missing. PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE, Manifest.permission.ACCESS_FINE_LOCATION, true); } else if (mMap != null) { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps(); return; } // Access to the location has been granted to the app. mMap.setMyLocationEnabled(true); // mMap.setLocationSource(mLocationSource); // mMap.setOnMapLongClickListener(mLocationSource); // Log.d(TAG, "enableMyLocation()"); if (selectedLocation != null) { mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(selectedLocation, 15)); } } }
From source file:com.adampmarshall.speedo.LocationActivity.java
@Override protected void onStart() { super.onStart(); // Check if the GPS setting is currently enabled on the device. // This verification should be done during onStart() because the system // calls this method // when the user returns to the activity, which ensures the desired // location provider is // enabled each time the activity resumes from the stopped state. LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); if (!gpsEnabled) { // Build an alert dialog here that requests that the user enable // the location services, then when the user clicks the "OK" button, // call enableLocationSettings() new EnableGpsDialogFragment().show(getSupportFragmentManager(), "enableGpsDialog"); }// w w w . j a va 2s . co m }
From source file:com.example.ogadrive.HomeActivity2.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home2); Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar.setNavigationIcon(R.drawable.home); //mToolbar.setLogo(R.drawable.ic_launcher); setSupportActionBar(mToolbar);//from w ww .j a va 2 s . c om bundle = getIntent().getExtras(); User user = (User) bundle.getSerializable("User"); setUser(user); mTitle = mDrawerTitle = getTitle(); // mPlanetTitles = getResources() // .getStringArray(R.array.Oga_options_array); mPlanetTitles = new String[] { "" + user.getName() + System.getProperty("line.separator") + "" + user.getPhone(), "Home", "Book Vehicle", "History", "Emergency Contact", "Support", "About" }; mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer // opens // mDrawerLayout.setDrawerShadow(R.drawable.ic_launcher, // GravityCompat.START); // set up the drawer's list view with items and click listener /*mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));*/ mDrawerList.setAdapter(new NavigationAdapter(this, mPlanetTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_launcher, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getSupportActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to // onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to // onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(1); } final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps(); } Intent intentLocationSerVice = new Intent(this, com.example.services.LocationUpdateService_2.class); LocationUpdateService_2.token = user.getToken(); startService(intentLocationSerVice); }
From source file:me.isassist.isa.MainActivity.java
public void showMainFragment() { //show the main fragment with instruction picture Fragment mainFragment = new MainFragment(); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.fragment_container, mainFragment).commit(); // nie rusza - nie wiem czemu ale sprawia problemy final LocationManager manager = (LocationManager) getSystemService(this.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps();/*from w ww . j av a 2 s . c o m*/ } }
From source file:fr.louisbl.cordova.locationservices.CordovaLocationServices.java
private boolean isGPSdisabled() { LocationManager lm = null; boolean gps_enabled; if (lm == null) lm = (LocationManager) this.cordova.getActivity().getSystemService(Context.LOCATION_SERVICE); try {//from w ww. jav a2 s . c o m gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ex) { ex.printStackTrace(); gps_enabled = false; } return !gps_enabled; }
From source file:com.facebook.react.modules.location.LocationModule.java
@Nullable private String getValidProvider(LocationManager locationManager, boolean highAccuracy) { String provider = highAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER; if (!locationManager.isProviderEnabled(provider)) { provider = provider.equals(LocationManager.GPS_PROVIDER) ? LocationManager.NETWORK_PROVIDER : LocationManager.GPS_PROVIDER; if (!locationManager.isProviderEnabled(provider)) { return null; }/*from w w w .j av a 2 s . c o m*/ } // If it's an enabled provider, but we don't have permissions, ignore it int finePermission = ContextCompat.checkSelfPermission(getReactApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION); if (provider.equals(LocationManager.GPS_PROVIDER) && finePermission != PackageManager.PERMISSION_GRANTED) { return null; } return provider; }
From source file:net.jongrakko.zipsuri.activity.RegisterExpertActivity.java
@Override public boolean onMyLocationButtonClick() { LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (!mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { ProgressManger.showToast(" ."); } else {//from w w w . ja va 2s . c o m ProgressManger.showToast(" ..."); } return false; }
From source file:com.example.scandevice.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = getApplicationContext();//from w ww . j av a2 s .c om LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); // Getting the name of the provider that meets the criteria provider = locationManager.getBestProvider(criteria, true); if (provider == null && !locationManager.isProviderEnabled(provider)) { // Get the location from the given provider List<String> list = locationManager.getAllProviders(); for (int i = 0; i < list.size(); i++) { //Get device name; String temp = list.get(i); //check usable if (locationManager.isProviderEnabled(temp)) { provider = temp; break; } } } //get location where reference last. Location location = locationManager.getLastKnownLocation(provider); if (location == null) Toast.makeText(this, "There are no available position information providers.", Toast.LENGTH_SHORT) .show(); else //GPS start from last location. onLocationChanged(location); // Set by <content src="index.html" /> in config.xml loadUrl(launchUrl); }
From source file:it.unipr.informatica.autobusparma.MappaFragment.java
public void initLoc(LocationManager locMan) { locMan = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); isGPSEnabled = locMan.isProviderEnabled(LocationManager.GPS_PROVIDER); if (!isGPSEnabled) { Toast.makeText(getActivity(), "GPS non attivo. \nVai nelle opzioni per attivarlo.", Toast.LENGTH_SHORT) .show();//from www . j a v a2s .c o m } if (!isOnline()) { Toast.makeText(getActivity(), "Internet non attivo. \nVai nelle opzioni per attivarlo.", Toast.LENGTH_SHORT).show(); } }