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:org.runnerup.tracker.GpsStatus.java

public boolean isEnabled() {
    LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    return lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
}

From source file:ca.rmen.android.networkmonitor.app.prefs.PreferenceFragmentActivity.java

/**
 * Checks if we have either the GPS or Network location provider enabled. If not, shows a popup dialog telling the user they should go to the system
 * settings to enable location tracking.
 *///from  w w  w.java 2 s .c  o  m
private void checkLocationSettings() {
    // If the user chose high accuracy, make sure we have at least one location provider.
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
            || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))) {
        DialogFragmentFactory.showConfirmDialog(this, getString(R.string.no_location_confirm_dialog_title),
                getString(R.string.no_location_confirm_dialog_message), ID_ACTION_LOCATION_SETTINGS, null);
    } else {
        finish();
    }
}

From source file:com.rsamadhan.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    LocationManager service = (LocationManager) 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) {
        showGPSDialog();/*from  ww  w .  j  av  a 2  s  . c  o m*/
    }
}

From source file:com.jmstudios.redmoon.receiver.AutomaticFilterChangeReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (DEBUG)/*from ww  w  . ja v a 2 s .com*/
        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:de.grundid.plusrad.MainActivity.java

private void proccessWithLocationPermission() {
    final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        buildAlertMessageNoGps();/*from w ww  .j  a va  2s .co  m*/
    } else {
        startActivity(new Intent(this, RecordingActivity.class));
    }
}

From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.FixturesFragment.java

/**
 * Updates the GPS status/*from  w w  w .jav a  2s. c  om*/
 */
private void updateGPSStatusDisplay() {
    final LocationManager locationManager = (LocationManager) getActivity()
            .getSystemService(Context.LOCATION_SERVICE);
    gps.setText(Boolean.toString(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)));
}

From source file:studioidan.com.parsetest.MainActivity.java

private void turnGpsOn() {
    final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(//from  ww w. j a v  a2s.  co  m
                " ? ? ?...??   ???")
                .setCancelable(false).setPositiveButton("", new DialogInterface.OnClickListener() {
                    public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                            @SuppressWarnings("unused") final int id) {
                        startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                    }
                }).setNegativeButton("? ", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog,
                            @SuppressWarnings("unused") final int id) {
                        dialog.cancel();
                    }
                });
        final AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:smp.project.whereareyou.MapActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // loading maps
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    Intent intent = getIntent();/*from w  w  w  .j ava2s .  co m*/
    if (intent.getStringExtra("whoiam").equals(c.CLIENT)) {
        new ClientTask().execute(intent.getStringExtra("severAddr"));
    } else {
        new ServerTask().execute(intent.getStringExtra("fixme: no text"));
    }
    LocationManager manager = (LocationManager) getSystemService(MapActivity.LOCATION_SERVICE);
    if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        cu.showSettingsAlert(this, c.NOGPS_MSG, c.ACTION_LOC_SRC_SETT);
    }
    setUpMapIfNeeded();
}

From source file:com.findcab.driver.activity.Signup.java

private boolean initGPS() {
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    // GPS????/*from  w ww.ja  va2 s.  c  om*/
    if (!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
        Toast.makeText(this, "GPS is not open,Please open it!", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivityForResult(intent, 0);

        return false;
    } else {
        Toast.makeText(this, "GPS is ready", Toast.LENGTH_SHORT);
    }
    return true;
}

From source file:com.google.transporttracker.TrackerActivity.java

/**
 * Third and final validation check - ensures GPS is enabled, and if not, prompts to
 * enable it, otherwise all checks pass so start the location tracking service.
 *///w ww . j a v a 2 s.com
private void checkGpsEnabled() {
    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        reportGpsError();
    } else {
        resolveGpsError();
        startLocationService();
    }
}