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:com.xortech.sender.SenderSend.java

/**
 * METHOD TO SHOW ALERT DIALOG ASKING USER TO ENABLE HIS/HER GPS
 * // w  ww .  ja v a 2 s. c  om
 * @param NONE
 * 
 * */
public void showSettingsAlert() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);

    // SET DIALOG TITLE
    alertDialog.setTitle("GPS is settings");

    // SET DIALOG MESSAGE
    alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");

    // PRESS THE SETTIGNS BUTTON, SHOW OPTIONS
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            context.startActivity(intent);
        }
    });

    // ON CANCEL PRESS
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    // SHOW ALERT MESSAGE
    alertDialog.show();
}

From source file:com.eeshana.icstories.activities.UploadVideoActivity.java

@SuppressLint("NewApi")
@Override/*from   ww w.  ja v a2s .c  om*/
public void onClick(View v) {
    if (v.getId() == uploadButton.getId()) {
        if (connectionDetector.isConnectedToInternet()) {
            title = titleEditText.getText().toString();
            description = descriptionEditText.getText().toString();
            flag = isAssignment;
            my_location = locationEditText.getText().toString();
            if (title.equalsIgnoreCase("") || description.equalsIgnoreCase("")) {
                showCustomToast.showToast(UploadVideoActivity.this, "Title and Description both are required");
            } else {

                Log.e("location2", my_location);

                //new UplodTask(getApplicationContext()).execute();
                if (title.length() <= 30 && title.length() >= 4 && description.length() >= 4
                        && description.length() <= 150 && my_location.length() <= 30) {//&& my_location.matches(pattern) && title.matches(pattern) && description.matches(pattern)){
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                        new UplodTask(getApplicationContext())
                                .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    } else {
                        new UplodTask(getApplicationContext()).execute();
                    }

                } else {
                    //                  if(!title.matches(pattern)){
                    //                     titleEditText.setError("Title contains one or more invalid characters. Please check.");
                    //                  }
                    //                  if(!description.matches(pattern)){
                    //                     descriptionEditText.setError("Description contains one or more invalid characters. Please check");
                    //                  }
                    //                  if(!my_location.matches(pattern)){
                    //                     locationEditText.setError("Location contains one or more invalid characters. Please check");
                    //                  }
                    if (title.length() < 4) {
                        titleEditText.setError("Title must be min 4 characters.");
                    }
                    if (description.length() < 4) {
                        descriptionEditText.setError("Description must be min 4 characters.");
                    }
                    if (title.length() > 30) {
                        titleEditText.setError("Title must be max 30 characters.");
                    }
                    if (description.length() > 150) {
                        descriptionEditText.setError("Description must be max 150 characters.");
                    }
                    if (my_location.length() > 30) {
                        descriptionEditText.setError("Location must be max 30 characters.");
                    }
                }
            }
        } else {
            showCustomToast.showToast(UploadVideoActivity.this, "Please check your internet connection.");
        }
    } else if (v.getId() == isAssignmentButton.getId()) {
        if (isAssignment.equalsIgnoreCase("NO")) {
            isAssignment = "YES";
            isAssignmentButton.setText("YES");
        } else {
            isAssignment = "NO";
            isAssignmentButton.setText("NO");
        }
    } else if (v.getId() == wallRelativeLayout.getId()) {
        Intent i = new Intent(UploadVideoActivity.this, WallActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(i);
        finish();
    } else if (v.getId() == settingsRelativeLayout.getId()) {
        Intent i = new Intent(UploadVideoActivity.this, SettingsActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(i);
        finish();
    } else if (v.getId() == okButton.getId()) {
        //go to settings page to enable GPS
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivityForResult(intent, REQUEST_CODE);
        locationDialog.dismiss();
    } else if (v.getId() == cancelButton.getId()) {
        locationDialog.dismiss();
    }

}

From source file:com.tml.sharethem.receiver.ReceiverActivity.java

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Your GPS seems to be disabled, Please enabled it to proceed with p2p movie sharing")
            .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                    dialog.dismiss();//from  w  w  w . j  av a2  s .  c o  m
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    dialog.cancel();
                    finish();
                }
            });
    final AlertDialog alert = builder.create();
    alert.show();

}

From source file:org.odk.collect.android.activities.GeoTraceOsmMapActivity.java

private void showGPSDisabledAlertToUser() {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setMessage(getString(R.string.enable_gps_message)).setCancelable(false)
            .setPositiveButton(getString(R.string.enable_gps), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
                }/*from  w w w  . j ava 2 s  .  com*/
            });
    alertDialogBuilder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    AlertDialog alert = alertDialogBuilder.create();
    alert.show();
}

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

private void getAccurateLocation2(final GoogleMap googleMap) {
    final FragmentActivity activity = getActivity();
    if (activity == null) {
        return;//from  ww  w  .j  a  va 2 s .  com
    }
    final ConnectivityManager connectivityManager = (ConnectivityManager) activity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
            && (networkInfo != null && networkInfo.isConnected())) {
        if (simulatedLocation == null) {
            if (ActivityCompat.checkSelfPermission(activity.getApplicationContext(),
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(activity.getApplicationContext(),
                            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                return;
            }

            locationManager = (LocationManager) activity.getApplicationContext()
                    .getSystemService(Context.LOCATION_SERVICE);

            final List<String> providers = locationManager.getProviders(true);
            Location finalLocation = null;

            for (String provider : providers) {
                if (ActivityCompat.checkSelfPermission(activity.getApplicationContext(),
                        Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                        && ActivityCompat.checkSelfPermission(activity.getApplicationContext(),
                                Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    return;
                }

                final Location suggestedLocation = locationManager.getLastKnownLocation(provider);

                if (suggestedLocation == null) {
                    continue;
                }
                Log.i("Location Provider",
                        "provider=" + suggestedLocation.getProvider() + " time="
                                + new SimpleDateFormat("yyyy MMM dd HH:mm:ss")
                                        .format(suggestedLocation.getTime())
                                + " accuracy=" + suggestedLocation.getAccuracy() + " lat="
                                + suggestedLocation.getLatitude() + " lng=" + suggestedLocation.getLongitude());

                if (finalLocation == null) {
                    finalLocation = suggestedLocation;
                } else if (suggestedLocation.getTime() - finalLocation.getTime() > 1000) {
                    // drop more than 1000ms old data
                    finalLocation = suggestedLocation;
                } else if (suggestedLocation.getAccuracy() < finalLocation.getAccuracy()) {
                    // picks more acculate one
                    finalLocation = suggestedLocation;
                }
            }

            location = finalLocation;
        } else {
            location = simulatedLocation;
        }
        if (location != null) {
            final LatLng userLocation = new LatLng(location.getLatitude(), location.getLongitude());

            mMap.addMarker(new MarkerOptions().position(userLocation).title("Your Location"));

            mMap.moveCamera(CameraUpdateFactory.newLatLng(userLocation));
            mMap.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);

            getCars(location);
        } else {
            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);
        }
    } else {
        if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            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 (networkInfo == null) {
                networkIntentNeeded = true;
            }
        } else {
            if (networkInfo == null) {
                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.waz.zclient.pages.main.conversation.LocationFragment.java

private void showLocationServicesDialog() {
    ViewUtils.showAlertDialog(getContext(), R.string.location_sharing__enable_system_location__title,
            R.string.location_sharing__enable_system_location__message,
            R.string.location_sharing__enable_system_location__confirm,
            R.string.location_sharing__enable_system_location__cancel, new DialogInterface.OnClickListener() {
                @Override/*from  w  w  w  .j a  v  a 2  s .c  o  m*/
                public void onClick(DialogInterface dialog, int which) {
                    Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    getContext().startActivity(myIntent);
                }
            }, null);
}

From source file:com.taw.gotothere.GoToThereActivity.java

/**
 * Display a dialog asking the user if they want to access the location
 * settings//from   ww  w  .j  a  va  2  s .  c o  m
 */
private void displayLocationSettingsDialog() {
    new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.gps_dialog_title))
            .setMessage(getResources().getString(R.string.gps_dialog_text))
            .setPositiveButton(getResources().getString(R.string.yes_button_label),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                        }
                    })
            .setNegativeButton(getResources().getString(R.string.no_button_label),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    })
            .show();
}

From source file:com.google.android.gms.samples.vision.ocrreader.MainActivity.java

private void _getLocation() {
    // Get the location manager
    Coordinates = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);

    if (ActivityCompat.checkSelfPermission(getApplicationContext(),
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(getApplicationContext(),
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[] { Manifest.permission.ACCESS_FINE_LOCATION,
                        Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.INTERNET },
                PackageManager.PERMISSION_GRANTED);
    }/* www  .  jav  a2s . c o m*/

    GPSEnabled = true;
    NetworkEnabled = true;

    try {
        GPSEnabled = Coordinates.isProviderEnabled(LocationManager.GPS_PROVIDER);
    } catch (Exception ex) {
    }

    try {
        NetworkEnabled = Coordinates.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    } catch (Exception ex) {
    }

    if (!GPSEnabled) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setMessage("GPS is Required but Disabled : Enable GPS , Restart App.");

        alertDialogBuilder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                finish();
            }
        });

        alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });

        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();

    }

    if (!NetworkEnabled) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setMessage("Network is Required but Disabled : Enable Network , Restart App.");

        alertDialogBuilder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                finish();
            }
        });

        alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });

        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }

    if (GPSEnabled && NetworkEnabled) {
        Coordinates.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {

            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {

            }

            @Override
            public void onProviderEnabled(String provider) {

            }

            @Override
            public void onProviderDisabled(String provider) {

            }
        });
        try {
            location = Coordinates.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            lat = location.getLatitude();
            lon = location.getLongitude();
        } catch (Exception e) {

        }
    }
}

From source file:org.odk.collect.android.activities.GeoPointMapActivity.java

private void showGPSDisabledAlertToUser() {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setMessage(getString(R.string.gps_enable_message)).setCancelable(false)
            .setPositiveButton(getString(R.string.enable_gps), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
                }// w w w .ja  va2  s.co  m
            });
    alertDialogBuilder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    AlertDialog alert = alertDialogBuilder.create();
    alert.show();
}

From source file:com.bangz.smartmute.services.LocationMuteService.java

private void NotificationUserFailed() {

    NotificationCompat.Builder nb = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_notification)
            .setColor(getResources().getColor(R.color.theme_accent_2))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setAutoCancel(true);

    //        LocationManager lm = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
    //        boolean bProviderEnabled =
    //                lm.isProviderEnabled(LocationManager.GPS_PROVIDER) |
    //                lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

    int locationmode = ApiAdapterFactory.getApiAdapter().getLocationMode(this);
    if (locationmode <= ApiAdapter.LOCATION_MODE_SENSORS_ONLY) {
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        nb.setContentTitle(getResources().getString(R.string.location_provider_disabled_title));
        nb.setContentText(getResources().getString(R.string.location_provider_disabled_text));
        nb.setContentIntent(pi);//  www . ja  va 2 s . c  o  m
    } else {
        // GPS and Network location provider is OK. let use try again
        Intent intent = new Intent(ACTION_START_GEOFENCES, null, this, LocationMuteService.class);
        PendingIntent pi = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        nb.setContentTitle(getResources().getString(R.string.geo_not_available_retry_title));
        nb.setContentText(getResources().getString(R.string.geo_not_available_retry_text));
        nb.setContentIntent(pi);
    }
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    nm.notify(GEOFENCE_NOT_AVLIABLE_NOTIFICATION_ID, nb.build());

}