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:com.detroitteatime.autocarfinder.Main.java

public static void makeSureGPSIsOn(Context c) {
    LocationManager service = (LocationManager) c.getSystemService(LOCATION_SERVICE);
    boolean enabled = service.isProviderEnabled(LocationManager.GPS_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 (!enabled) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        c.startActivity(intent);//  w  w w. j  a v  a 2 s .c om
    }

}

From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListActivity.java

/**
 * checks if location services are available
 *///  w w w .  j av a 2 s  .  c om
public static boolean isGPSAvailable(Context context) {
    if (context == null) {
        return false;
    }
    LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    return manager.isProviderEnabled(LocationManager.GPS_PROVIDER)
            || manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

}

From source file:id.satusatudua.sigap.service.LocationReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    if (!BenihUtils.isMyServiceRunning(context, LocationService.class)) {
        context.startService(new Intent(context, LocationService.class));
    }//from   w  ww.  j  a va2  s  .co m

    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    boolean anyLocationProv = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    anyLocationProv |= locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

    if (!anyLocationProv) {
        Notification notification = new NotificationCompat.Builder(context).setContentTitle("Sigap")
                .setContentText("Fitur lokasi tidak aktif.")
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
                .setSmallIcon(R.mipmap.ic_launcher).setOngoing(true).setAutoCancel(true)
                .setStyle(new android.support.v4.app.NotificationCompat.BigTextStyle()
                        .bigText("Aktifkan fitur lokasi agar Sigap bisa berjalan dengan baik."))
                .build();

        NotificationManagerCompat.from(SigapApp.pluck().getApplicationContext()).notify(25061993, notification);
    } else {
        NotificationManagerCompat.from(SigapApp.pluck().getApplicationContext()).cancel(25061993);
    }
}

From source file:com.neton.cordova.diagnostic.Diagnostic.java

private boolean isLocationProviderEnabled(String provider) {
    LocationManager locationManager = (LocationManager) cordova.getActivity()
            .getSystemService(Context.LOCATION_SERVICE);
    return locationManager.isProviderEnabled(provider);
}

From source file:com.collectme.cordova.calgeolocation.CalGeolocation.java

private boolean isLocationProviderEnabled(String provider) {
    LocationManager locationManager = (LocationManager) this.cordova.getActivity()
            .getSystemService(Context.LOCATION_SERVICE);
    return locationManager.isProviderEnabled(provider);
}

From source file:br.com.taxisimples.cordova.plugin.Checker.java

public boolean isGpsEnabled() {
    LocationManager locationManager = (LocationManager) this.cordova.getActivity()
            .getSystemService(this.cordova.getActivity().LOCATION_SERVICE);
    return locationManager.isProviderEnabled("gps");
}

From source file:net.quranquiz.ui.QQMap.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);//from   w ww .j a v a  2s.co m
    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    map.setOnMarkerClickListener((OnMarkerClickListener) this);

    cairo = new LatLng(30.1, 31.45);

    LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
    boolean enabledGPS = service.isProviderEnabled(LocationManager.GPS_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) {
        Toast.makeText(this, "GPS signal not found", Toast.LENGTH_LONG).show();
        startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
    }

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    provider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(provider);

    // Initialize the location fields
    if (location != null) {
        Toast.makeText(this, "Selected Provider " + provider, Toast.LENGTH_SHORT).show();
        meMarker = map.addMarker(
                new MarkerOptions().position(cairo).title("That's Me").snippet("a normal QuranQuiz Node!")
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

        map.moveCamera(CameraUpdateFactory.newLatLngZoom(cairo, 12.0f));

        onLocationChanged(location);
    } else {

        //do something
    }

}

From source file:com.lauszus.launchpadflightcontrollerandroid.app.MapFragment.java

@Override
public void onResume() {
    super.onResume();
    LocationManager locationManager = (LocationManager) getActivity()
            .getSystemService(Context.LOCATION_SERVICE);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        new AlertDialog.Builder(getActivity())
                .setMessage("Your GPS seems to be disabled, do you want to enable it?").setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                    }//w w w .j  a  v a  2s  .  c  om
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        dialog.cancel();
                        Toast.makeText(getActivity(), "GPS must be on in order to use this application!",
                                Toast.LENGTH_LONG).show();
                        getActivity().finish();
                    }
                }).create().show();
    } else {
        setUpMapIfNeeded();
        if (ActivityCompat.checkSelfPermission(getActivity(),
                Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            Location location = locationManager
                    .getLastKnownLocation(locationManager.getBestProvider(new Criteria(), false));
            if (location != null) {
                LatLng myLocation = new LatLng(location.getLatitude(), location.getLongitude());
                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myLocation, 19.0f));
            }
        }
    }
}

From source file:com.yammy.meter.map.MainMapBengkel.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.isvo_map_bengkel);
    this.jarak = (TextView) this.findViewById(R.id.map_bengkel_length);

    int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    if (result != ConnectionResult.SUCCESS) {
        GooglePlayServicesUtil.getErrorDialog(result, MainMapBengkel.this, 1).show();
    } else {//from   w ww. j  a v a  2 s. c o  m
        map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getBaseContext());

        map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        map.setIndoorEnabled(false);
        bundle = getIntent().getExtras();
        try {
            data_pos = new LatLng(Double.parseDouble(bundle.getString("lat")),
                    Double.parseDouble(bundle.getString("long")));
            Toast.makeText(getBaseContext(), bundle.getString("lat") + "," + bundle.getString("long"),
                    Toast.LENGTH_LONG).show();
        } catch (NumberFormatException e) {
            Toast.makeText(getBaseContext(), "Mencari lokasi saat ini", Toast.LENGTH_SHORT).show();
        }

        /**
         * mulai edan dari ini ke bawah
         */
        LocationManager service = (LocationManager) this.getSystemService(LOCATION_SERVICE);
        boolean enabledGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (!enabledGPS) {
            Toast.makeText(this, "GPS tidak ditemukan", Toast.LENGTH_LONG).show();
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
        }
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, this);
        if (location != null && location.getTime() > Calendar.getInstance().getTimeInMillis() - 2 * 60 * 1000) {
            Toast.makeText(getApplicationContext(),
                    "Current Location : " + location.getLatitude() + "," + location.getLongitude(),
                    Toast.LENGTH_LONG).show();
            drawMarker(location);
        } else {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        }
    }
}

From source file:com.jmstudios.redmoon.preference.LocationPreference.java

public void searchLocation(boolean explicitRequest) {
    if (mIsSearchingLocation)
        mIsSearchExplicit = explicitRequest || mIsSearchExplicit;
    else/*from  w  w  w  . ja  va2  s.  c o m*/
        mIsSearchExplicit = explicitRequest;
    if (!mIsSearchingLocation) {
        if (DEBUG)
            Log.i(TAG, explicitRequest ? "Searching location on explicit request"
                    : "Searching location automatically");
        mIsSearchingLocation = true;

        LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
        if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
                && ContextCompat.checkSelfPermission(mContext,
                        Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            LocationListener listener = new LocationUpdateListener(mContext, this);
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener);
        } else {
            handleLocationSearchFailed();
        }
    }

    if (mIsSearchExplicit && mIsSearchingLocation) {
        setSummary(mContext.getString(R.string.searching_location));
    }
}