Example usage for android.provider Settings ACTION_LOCATION_SOURCE_SETTINGS

List of usage examples for android.provider Settings ACTION_LOCATION_SOURCE_SETTINGS

Introduction

In this page you can find the example usage for android.provider Settings ACTION_LOCATION_SOURCE_SETTINGS.

Prototype

String ACTION_LOCATION_SOURCE_SETTINGS

To view the source code for android.provider Settings ACTION_LOCATION_SOURCE_SETTINGS.

Click Source Link

Document

Activity Action: Show settings to allow configuration of current location sources.

Usage

From source file:wanthavers.mad.cs.fau.de.wanthavers_android.desirelist.DesireListFragment.java

private void showAlert() {
    final android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(getActivity());
    dialog.setTitle(getString(R.string.enable_gps)).setMessage(getString(R.string.enable_gps_text_desirelist))
            .setPositiveButton(getString(R.string.enable_gps_settings), new DialogInterface.OnClickListener() {
                @Override//from w  w  w .ja  v  a2s .  co  m
                public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                    Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    startActivity(myIntent);
                    getCurrentGpsPosition();
                }
            }).setNegativeButton(getString(R.string.enable_gps_cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                }
            });
    dialog.show();
}

From source file:com.example.isse.weatherapp.ui.WeatherListActivity.java

/**
 * Function to show settings alert dialog
 *///w  w  w . ja  v a 2s .  c o m
public void showSettingsAlert() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

    // Setting Dialog Title
    alertDialog.setTitle(R.string.GPS_Setting);

    // Setting Dialog Message
    alertDialog.setMessage(R.string.GPS_Setting_message);

    // On pressing Settings button
    alertDialog.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            mContext.startActivity(intent);
        }
    });

    // on pressing cancel button
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    // Showing Alert Message
    alertDialog.show();
}

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);//from   w w w  .  jav  a  2s  .  c  o m
    }

}

From source file:org.odk.collect.android.map.GoogleMapFragment.java

protected void showGpsDisabledAlert() {
    gpsErrorDialog = new AlertDialog.Builder(getActivity()).setMessage(getString(R.string.gps_enable_message))
            .setCancelable(false)/* www. j  a va2 s  .  c  o  m*/
            .setPositiveButton(getString(R.string.enable_gps),
                    (dialog, id) -> startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                            0))
            .setNegativeButton(getString(R.string.cancel), (dialog, id) -> dialog.cancel()).create();
    gpsErrorDialog.show();
}

From source file:activities.GatewayActivity.java

@Override
public void onOKChooseNetworkForLocationClick() {
    enableSettings(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
}

From source file:fr.cph.chicago.util.Util.java

/**
 * Function to show settings alert dialog
 *///from  w ww  . j av a 2  s.c  o m
static void showSettingsAlert(@NonNull final Activity activity) {
    new Thread() {
        public void run() {
            activity.runOnUiThread(() -> {
                final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
                alertDialogBuilder.setTitle("GPS settings");
                alertDialogBuilder.setMessage(
                        "GPS is not enabled. Do you want to go to settings main.java.fr.cph.chicago.res.menu?");
                alertDialogBuilder.setCancelable(false).setPositiveButton("Yes", (dialog, id) -> {
                    final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    activity.startActivity(intent);
                }).setNegativeButton("No", (dialog, id) -> dialog.cancel());
                final AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            });
        }
    }.start();
}

From source file:com.appsimobile.appsii.module.home.YahooLocationChooserDialogFragment.java

void onEnableLocationClicked() {
    Intent locationIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    startActivity(locationIntent);

    dismiss();
}

From source file:com.kentli.cycletrack.RecordingActivity.java

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(//from www  .jav  a2s .  co  m
            "Your phone's GPS is disabled. CycleTracks needs GPS to determine your location.\n\nGo to System Settings now to enable GPS?")
            .setCancelable(false).setPositiveButton("GPS Settings...", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    final ComponentName toLaunch = new ComponentName("com.android.settings",
                            "com.android.settings.SecuritySettings");
                    final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    intent.setComponent(toLaunch);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivityForResult(intent, 0);
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    dialog.cancel();
                }
            });
    final AlertDialog alert = builder.create();
    alert.show();
}

From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.AnalyzeMyDriving.java

private void getAccurateLocation(final GoogleMap googleMap) {
    final FragmentActivity activity = getActivity();
    if (activity == null) {
        Log.e("getAccurateLocation", "do nothing as getActivity()==null");
        if (locationManager != null) {
            requestLocationUpdates(false);
        }//from  w w  w  . ja v a  2 s.c  om
        return;
    }
    final ConnectivityManager connectivityManager = (ConnectivityManager) activity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

    final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    final boolean networkConnected = networkInfo != null && networkInfo.isConnected();
    if (gpsEnabled && networkConnected) {
        if (!checkCurrentLocation()) {
            Log.e("Location Data", "Not Working!");
            //                Toast.makeText(getActivity().getApplicationContext(), "Please activate your location settings and restart the application!", Toast.LENGTH_LONG).show();
            getAccurateLocation(mMap);
            return;
        }
        if (mMap != null) {
            float zoom = mMap.getCameraPosition().zoom;
            zoom = Math.max(14, zoom);
            zoom = Math.min(18, zoom);

            mMap.clear();
            final LatLng newLocation = new LatLng(location.getLatitude(), location.getLongitude());
            //                if (!cameraSet) {
            mMap.moveCamera(CameraUpdateFactory.newLatLng(newLocation));
            mMap.animateCamera(CameraUpdateFactory.zoomTo(zoom), 2000, null);
            //                    cameraSet = true;
            //                }
            mMap.addMarker(new MarkerOptions().position(newLocation).title("Your Location")
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.models)));
        }
        final ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar();
        if (startedDriving) {
            if (!behaviorDemo) {
                // get credentials may be failed
                startedDriving = false;
                completeReservation(reservationId[0], false);
                return;
            }
            speedMessage = "" + Math.round(location.getSpeed() * 60 * 60 / 16.0934) / 100.0 + " MPH";
            supportActionBar.setTitle(speedMessage + " - Data not sent");

            tripCount += 1;
            if (tripCount % 10 == 0) {
                //                renderMapMatchedLocation()
            }
        } else if (deviceClient != null) {
            supportActionBar.setTitle("Press Start Driving when ready.");
        }
        if (behaviorDemo) {
            API.runInAsyncUIThread(new Runnable() {
                @Override
                public void run() {
                    if (deviceClient == null && needCredentials) {
                        createDeviceClient();
                        connectDeviceClient();
                    }
                    if (userUnlocked) {
                        sendLocation(location);
                    }
                }
            }, activity);
        }
    } else {
        if (!gpsEnabled) {
            Toast.makeText(activity.getApplicationContext(), "Please turn on your GPS", Toast.LENGTH_LONG)
                    .show();

            final Intent gpsIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivityForResult(gpsIntent, GPS_INTENT);

            if (!networkConnected) {
                networkIntentNeeded = true;
            }
        } else if (!networkConnected) {
            Toast.makeText(activity.getApplicationContext(), "Please turn on Mobile Data or WIFI",
                    Toast.LENGTH_LONG).show();

            final Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
            startActivityForResult(settingsIntent, SETTINGS_INTENT);
        }
    }
}

From source file:com.example.mapdemo.BasicMapDemoActivity.java

private void setGeoLocation() {
    latitude = (TextView) findViewById(R.id.lat);
    longitude = (TextView) findViewById(R.id.lon);
    altitude = (TextView) findViewById(R.id.alt);
    heading = (TextView) findViewById(R.id.hea);

    provText = (TextView) findViewById(R.id.prov);
    choice = (TextView) findViewById(R.id.choice);
    fineAcc = (CheckBox) findViewById(R.id.fineAccuracy);
    choose = (Button) findViewById(R.id.chooseRadio);
    // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the location provider
    criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE); //default

    // user defines the criteria
    choose.setOnClickListener(new View.OnClickListener() {
        @Override//from   w w  w . j av a  2s  .  c  o m
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (fineAcc.isChecked()) {
                criteria.setAccuracy(Criteria.ACCURACY_FINE);
                choice.setText("fine accuracy selected");
            } else {
                criteria.setAccuracy(Criteria.ACCURACY_COARSE);
                choice.setText("coarse accuracy selected");
            }
        }
    });
    criteria.setCostAllowed(false);
    // get the best provider depending on the criteria
    provider = locationManager.getBestProvider(criteria, false);
    // the last known location of this provider
    Location location = locationManager.getLastKnownLocation(provider);
    mylistener = new MyLocationListener();
    if (location != null) {
        mylistener.onLocationChanged(location);
    } else {
        // leads to the settings because there is no last known location
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
    }
    // location updates: at least 1 meter and 200 millsecs change
    locationManager.requestLocationUpdates(provider, 200, 1, mylistener);
}