Example usage for android.location LocationManager isProviderEnabled

List of usage examples for android.location LocationManager isProviderEnabled

Introduction

In this page you can find the example usage for android.location LocationManager isProviderEnabled.

Prototype

public boolean isProviderEnabled(String provider) 

Source Link

Document

Returns the current enabled/disabled status of the given provider.

Usage

From source file:net.digitalphantom.app.weatherapp.WeatherActivity.java

private void getWeatherFromCurrentLocation() {
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION, },
                GET_WEATHER_FROM_CURRENT_LOCATION);

        return;//from  w  ww . j av  a 2s.  co m
    }

    // system's LocationManager
    final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

    Criteria locationCriteria = new Criteria();

    if (isNetworkEnabled) {
        locationCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
    } else if (isGPSEnabled) {
        locationCriteria.setAccuracy(Criteria.ACCURACY_FINE);
    }

    locationManager.requestSingleUpdate(locationCriteria, this, null);
}

From source file:org.microg.gms.ui.PlacePickerActivity.java

@SuppressWarnings("MissingPermission")
private void updateMapFromLocationManager() {
    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    Location last = null;//from   w w w. j  a v a  2 s .c o m
    for (String provider : lm.getAllProviders()) {
        if (lm.isProviderEnabled(provider)) {
            Location t = lm.getLastKnownLocation(provider);
            if (t != null && (last == null || t.getTime() > last.getTime())) {
                last = t;
            }
        }
    }
    Log.d(TAG, "Set location to " + last);
    if (last != null) {
        mapView.map().setMapPosition(new MapPosition(last.getLatitude(), last.getLongitude(), 4096));
    }
}

From source file:org.croudtrip.activities.MainActivity.java

private boolean GPSavailable() {
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}

From source file:com.androidquery.simplefeed.activity.PlaceActivity.java

private void refreshButton() {

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    boolean enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);

    if (enabled) {
        aq.id(R.id.button_gps).gone();/*  w w w. j a va  2s.  c o  m*/
    } else {
        aq.id(R.id.button_gps).visible();
    }

    refreshHint();

}

From source file:digital.dispatch.TaxiLimoNewUI.GCM.GCMIntentService.java

private Location getLocationByProvider(String provider) {
    Location location = null;//from  www.  j  a  va 2 s.  c om

    LocationManager locationManager = (LocationManager) c.getSystemService(Context.LOCATION_SERVICE);

    try {
        if (locationManager.isProviderEnabled(provider)) {
            location = locationManager.getLastKnownLocation(provider);
        }
    } catch (IllegalArgumentException e) {
        Logger.d(TAG, "Cannot acces Provider " + provider);
    }

    return location;
}

From source file:org.gdg.frisbee.android.widget.FeedbackFragment.java

private void buildProperties() {
    addProperty(PROPERTY_MODEL, Build.MODEL);
    addProperty(PROPERTY_ANDROID_VERSION, VERSION.RELEASE);

    try {/*from w ww  . java 2  s  .c  om*/
        WifiManager cm = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
        WifiInfo e = cm.getConnectionInfo();
        SupplicantState mobileDataEnabled = e.getSupplicantState();
        addProperty(PROPERTY_WI_FI_ENABLED, mobileDataEnabled);
    } catch (Exception e) {
        Timber.d(e, "Wifi Manager problem.");
    }

    boolean mobileDataEnabled1 = false;
    ConnectivityManager cm1 = (ConnectivityManager) getActivity()
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    try {
        Class e1 = Class.forName(cm1.getClass().getName());
        Method resolution = e1.getDeclaredMethod("getMobileDataEnabled");
        resolution.setAccessible(true);
        mobileDataEnabled1 = (Boolean) resolution.invoke(cm1);
    } catch (Exception e) {
        Timber.d(e, "Mobil data problem.");
    }

    addProperty(PROPERTY_MOBILE_DATA_ENABLED, mobileDataEnabled1);

    try {
        LocationManager e2 = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        boolean resolution1 = e2.isProviderEnabled("gps");
        addProperty(PROPERTY_GPS_ENABLED, resolution1);
    } catch (Exception e) {
        Timber.d(e, "GPS problem.");
    }

    try {
        DisplayMetrics e3 = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(e3);
        String resolution2 = Integer.toString(e3.widthPixels) + "x" + Integer.toString(e3.heightPixels);
        addProperty(PROPERTY_SCREEN_RESOLUTION, resolution2);
    } catch (Exception e) {
        Timber.d(e, "Screen density problem.");
    }

    try {
        String e4 = getActivity().getClass().getSimpleName();
        addProperty(PROPERTY_ACTIVITY, e4);
    } catch (Exception e) {
        Timber.d(e, "Activity name problem.");
    }

    PackageManager manager = getActivity().getPackageManager();
    try {
        PackageInfo e = manager.getPackageInfo(getActivity().getPackageName(), 0);
        addProperty(PROPERTY_APP_VERSION_NAME, e.versionName);
        addProperty(PROPERTY_APP_VERSION_CODE, e.versionCode);
    } catch (PackageManager.NameNotFoundException var7) {
        Timber.d("Problem with PackageManager");
    }
}

From source file:com.example.angelina.travelapp.places.PlacesActivity.java

private boolean locationTrackingEnabled() {
    final LocationManager locationManager = (LocationManager) getApplicationContext()
            .getSystemService(Context.LOCATION_SERVICE);
    return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}

From source file:com.android.jhansi.designchallenge.MapFragment.java

@Override
public void onConnected(Bundle bundle) {
    Log.i(TAG, "Location services connected.");

    Location location = null;/*w w  w  .  j a v  a2 s .  c  o  m*/
    if (ActivityCompat.checkSelfPermission(getActivity(),
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        if (!ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                Manifest.permission.ACCESS_FINE_LOCATION)) {
            //} else {
            ActivityCompat.requestPermissions(getActivity(),
                    new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                    MY_PERMISSION_ACCESS_FINE_LOCATION);
        }
    } else {
        LocationManager mLocationManager = (LocationManager) getActivity()
                .getSystemService(Context.LOCATION_SERVICE);

        if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
        }

        location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

    }

    if (location == null) {
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
    } else {
        handleNewLocation(location);
    }

}

From source file:com.tonyandr.caminoguideoff.map.MapActivity.java

private void checkGPS() {
    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)
            && !lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        // Build the alert dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Where are you?");
        builder.setMessage("Please enable Location Services and GPS");
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override//  www  . j a  v a2s. com
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.setPositiveButton("Enable", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                // Show location settings when the user acknowledges the alert dialog
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(intent);
            }
        });
        Dialog alertDialog = builder.create();
        alertDialog.setCanceledOnTouchOutside(false);
        alertDialog.show();
    }
}

From source file:com.example.get_location.Get_location.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()
    }/*from   w  w  w  .java  2s.  c  o  m*/
}