Android App Development With AndroidCource: May 2018

Friday, 18 May 2018

How to show Location Setting Dialog Open in Location Manager


Check Enable Location(GPS) Setting Dialog in Location Manager.

Check Location Setting dialog is enable or not and how to show dialog and
enabled location service in android.Open dialog of GPS service in android and check when GPS Dialog is disable.
Create Custome Method to Check GPS Location Service dialog open in android.
public boolean isCheckGPS(){

        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){

            ISGPSEnable();
        }

        return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    }

Crete Method to Show Dialog in GPS Open And Click to Setting button to Dialog and
Go to your Loction Setting and Enabled your mobile Location and Enabled to
GPS Location. In this Method Use to implement background Current Location Latitude and Longitude
find and Require to Enable GPS In your Mobile to use this Methods to Permission Require and Enabled GPS.

private void ISGPSEnable() {
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("GPS Enable Setting");
        builder.setMessage("GPS is Not Enabled.");
        builder.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

        builder.show();
    }