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:edu.pdx.cecs.orcycle.Controller.java

private void transitionToLocationServices(Fragment f) {
    final ComponentName toLaunch = new ComponentName(COM_ANDROID_SETTINGS,
            COM_ANDROID_SETTINGS_SECURITY_SETTINGS);
    final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setComponent(toLaunch);//w w w  .  j av a2s.c  o m
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    f.startActivityForResult(intent, 0);
}

From source file:kn.uni.gis.foxhunt.GameActivity.java

private void registerOnGPS() {
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (!!!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);/*from   w  ww  . j a v a 2s. c om*/
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 2f, this);
    if (SettingsContext.getInstance().isUseNetwork()) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 500, 2f, this);
    }
}

From source file:com.mobicage.rogerthat.GetLocationActivity.java

@Override
protected void onServiceBound() {
    T.UI();//from  w w  w.  j  ava  2s . c  o m
    setContentView(R.layout.get_location);

    mProgressDialog = new ProgressDialog(this);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mProgressDialog.setMessage(getString(R.string.updating_location));
    mProgressDialog.setCancelable(true);
    mProgressDialog.setCanceledOnTouchOutside(true);
    mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            T.UI();
            if (mLocationManager != null) {
                try {
                    mLocationManager.removeUpdates(mLocationListener);
                } catch (SecurityException e) {
                    L.bug(e); // Should never happen
                }
            }
        }
    });
    mProgressDialog.setMax(10000);

    mUseGPS = (CheckBox) findViewById(R.id.use_gps_provider);
    mGetCurrentLocationButton = (Button) findViewById(R.id.get_current_location);
    mAddress = (EditText) findViewById(R.id.address);
    mCalculate = (Button) findViewById(R.id.calculate);

    mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (mLocationManager == null) {
        mGetCurrentLocationButton.setEnabled(false);
    } else {
        mUseGPS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked && !mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                    new AlertDialog.Builder(GetLocationActivity.this).setMessage(R.string.gps_is_not_enabled)
                            .setPositiveButton(R.string.yes, new SafeDialogInterfaceOnClickListener() {
                                @Override
                                public void safeOnClick(DialogInterface dialog, int which) {
                                    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                    startActivityForResult(intent, TURNING_ON_GPS);
                                }
                            }).setNegativeButton(R.string.no, new SafeDialogInterfaceOnClickListener() {
                                @Override
                                public void safeOnClick(DialogInterface dialog, int which) {
                                    mUseGPS.setChecked(false);
                                }
                            }).create().show();
                }
            }
        });

        mGetCurrentLocationButton.setOnClickListener(new SafeViewOnClickListener() {
            @Override
            public void safeOnClick(View v) {
                T.UI();
                if (mService.isPermitted(Manifest.permission.ACCESS_FINE_LOCATION)) {
                    getMyLocation();
                } else {
                    ActivityCompat.requestPermissions(GetLocationActivity.this,
                            new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                            PERMISSION_REQUEST_ACCESS_FINE_LOCATION);
                }
            }
        });
    }

    mCalculate.setOnClickListener(new SafeViewOnClickListener() {
        @Override
        public void safeOnClick(View v) {
            final ProgressDialog pd = new ProgressDialog(GetLocationActivity.this);
            pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            pd.setMessage(getString(R.string.updating_location));
            pd.setCancelable(false);
            pd.setIndeterminate(true);
            pd.show();
            final String addressText = mAddress.getText().toString();
            mService.postOnIOHandler(new SafeRunnable() {
                @Override
                protected void safeRun() throws Exception {
                    Geocoder geoCoder = new Geocoder(GetLocationActivity.this, Locale.getDefault());
                    try {
                        List<Address> addresses = geoCoder.getFromLocationName(addressText, 5);
                        if (addresses.size() > 0) {
                            Address address = addresses.get(0);
                            final Location location = new Location("");
                            location.setLatitude(address.getLatitude());
                            location.setLongitude(address.getLongitude());
                            mService.postOnUIHandler(new SafeRunnable() {
                                @Override
                                protected void safeRun() throws Exception {
                                    pd.dismiss();
                                    mLocation = location;
                                    showMap();
                                }
                            });
                            return;
                        }
                    } catch (IOException e) {
                        L.d("Failed to geo code address " + addressText, e);
                    }
                    mService.postOnUIHandler(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            pd.dismiss();
                            UIUtils.showLongToast(GetLocationActivity.this,
                                    getString(R.string.failed_to_lookup_address));
                        }
                    });
                }
            });
        }
    });
}

From source file:ca.ualberta.cs.drivr.GPSTracker.java

/**
 * Opens settings Activity to allow user to turn on GPS.
 *///  www . jav a2  s  .c  o m
public void enableGPS() {
    AlertDialog.Builder GPSDialog = new AlertDialog.Builder(mContext);

    GPSDialog.setTitle("Please turn on Location Settings");
    GPSDialog.setMessage("GPS and/or A Network Provider is Required");

    GPSDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            mContext.startActivity(intent);
        }
    });
    GPSDialog.show();
}

From source file:com.anthonykeane.speedzone.ActivityRecognitionIntentService.java

/**
 * Get a content Intent for the notification
 *
 * @return A PendingIntent that starts the device's Location Settings panel.
 *///from   w  w w  .j a v a  2 s .  com
private PendingIntent WhatToDoWhenNotificationIsClicked() {

    // Set the Intent action to open Location Settings
    Intent gpsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);

    // Create a PendingIntent to start an Activity
    return PendingIntent.getActivity(getApplicationContext(), 0, gpsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:com.emlago.sensorex.services.activity_recognition.ActivityRecognitionIntentService.java

/**
 * Get a content Intent for the notification
 *
 * @return A PendingIntent that starts the device's Location Settings panel.
 *//*from w w w. j a va2  s  . c o  m*/
private PendingIntent getContentIntent() {

    // Set the Intent action to open Location Settings
    Intent gpsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);

    // Create a PendingIntent to start an Activity
    return PendingIntent.getActivity(getApplicationContext(), 0, gpsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_poi_map);

    SupportMapFragment smf = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.f_map);

    gmm = new GoogleMapsModule(POIMapActivity.this, smf);

    if (gmm.googleMap != null) {

        // get and set map type from settings
        selectedMapType = getSelectedGoogleMapType();
        switchGoogleMapType(selectedMapType);

        gmm.addAllMarkers(POIMapActivity.this);
        gmm.googleMap.setOnMapClickListener(POIMapActivity.this);
        gmm.googleMap.setOnMarkerClickListener(POIMapActivity.this);
        gmm.googleMap.setOnInfoWindowClickListener(POIMapActivity.this);

        // Setting a custom info window adapter for the google map
        gmm.googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

            // Use default InfoWindow frame
            @Override/*  ww w. j a v a  2 s .c o  m*/
            public View getInfoWindow(Marker marker) {
                return null;
            }

            // Defines the contents of the InfoWindow
            @Override
            public View getInfoContents(Marker marker) {

                // Getting view from the layout file info_window_layout
                View v = getLayoutInflater().inflate(R.layout.custom_infowindow_popup, null);

                TextView tv;
                tv = (TextView) v.findViewById(R.id.snippet);
                tv.setText(marker.getSnippet());

                // Returning the view containing InfoWindow contents
                return v;

            }
        });
    }

    tvMapMessage = (TextView) findViewById(R.id.tv_map_message);

    tvMapMessage.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (!gmm.internetEnabled) {
                POIMapActivity.this.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
            } else if (!gmm.myLocationEnabled) {
                startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                        0);
            }

        }
    });

    tvMapDirectionsInfo = (TextView) findViewById(R.id.tv_map_directions_info);

    lockOrientation();
}

From source file:com.app.swaedes.swaedes.GPSTracker.java

/**
 * Function to show settings alert dialog
 * On pressing Settings button will lauch Settings Options
 * *///from w ww. j  a  v a2 s .co  m
public void showSettingsAlert() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

    // Setting Dialog Title
    alertDialog.setTitle("GPS is settings");

    // Setting Dialog Message
    alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");

    // On pressing Settings button
    alertDialog.setPositiveButton("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.fpil.android.remotesensor.MainDisplay.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

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

    Criteria locationCriteria = new Criteria();
    locationCriteria.setAccuracy(Criteria.ACCURACY_FINE);
    locationCriteria.setAltitudeRequired(false);
    locationCriteria.setBearingRequired(false);
    locationCriteria.setCostAllowed(true);
    locationCriteria.setPowerRequirement(Criteria.NO_REQUIREMENT);

    locationProviderName = locationManager.getBestProvider(locationCriteria, true);

    if (ActivityCompat.checkSelfPermission(getActivity(),
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(getActivity(),
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(getActivity(), R.string.turn_on_gps, Toast.LENGTH_LONG).show();
        Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        this.startActivity(myIntent);
    }//from   ww  w  .  j  a  v  a  2  s . c om

    if (locationProviderName != null && locationManager.isProviderEnabled(locationProviderName)) {
        // Provider is enabled
        Toast.makeText(getActivity(), R.string.gps_available, Toast.LENGTH_LONG).show();
    } else {
        // Provider not enabled, prompt user to enable it
        Toast.makeText(getActivity(), R.string.turn_on_gps, Toast.LENGTH_LONG).show();
        Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        this.startActivity(myIntent);
    }
}

From source file:nz.co.android.cowseye2.activity.RecordLocationActivity.java

private void buildAlertMessageNoGps(final Bundle savedInstanceState) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(this.getResources().getString(R.string.gps_message)).setCancelable(false)
            .setPositiveButton(this.getResources().getString(R.string.positive_button_title),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(final DialogInterface dialog, final int id) {
                            startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                            setupManagers(savedInstanceState);
                        }/*from w w  w  . j  a v  a2  s .  c o m*/
                    })
            .setNegativeButton(this.getResources().getString(R.string.negative_button_title),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(final DialogInterface dialog, final int id) {
                            dialog.cancel();
                            setupManagers(savedInstanceState);
                        }
                    });
    final AlertDialog alert = builder.create();
    alert.show();
}