I want to show dialog box for turn on GPS when GPS is disable .
See the image. When i click on YES then should be automatically turn on my GPS without going into setting.
So , how can i enable GPS by select YES option ?
I want to show dialog box for turn on GPS when GPS is disable .
See the image. When i click on YES then should be automatically turn on my GPS without going into setting.
So , how can i enable GPS by select YES option ?
This is part of Google play service api since 7.0 called SettingsApi
.
Location settings - While the FusedLocationProviderApi
combines multiple sensors to give you the optimal location, the accuracy of the location your app receives still depends greatly on the settings enabled on the device (GPS, wifi, airplane mode, and others). Using the new SettingsApi class, you can bring up a Location Settings dialog which displays a one-touch control for users to change their settings without leaving your app.
To use this API, first create a GoogleApiClient which supports at least LocationServices.API
. Then connect the client to Google Play services:
mGoogleApiClient = new GoogleApiClient.Builder(context)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build()
...
mGoogleApiClient.connect();
Then create a LocationSettingsRequest.Builder
and add all of the LocationRequests that the app will be using:
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequestHighAccuracy)
.addLocationRequest(mLocationRequestBalancedPowerAccuracy);
For next steps please check here: https://developers.google.com/android/reference/com/google/android/gms/location/SettingsApi
IMPORTANT: If the status code is RESOLUTION_REQUIRED, the client can call startResolutionForResult(Activity, int) to bring up a dialog, asking for user's permission to modify the location settings to satisfy those requests.
The result of the dialog will be returned via onActivityResult(int, int, Intent). If the client is interested in which location providers are available, it can retrieve a LocationSettingsStates from the Intent by calling fromIntent(Intent)
Also please refer to this official repo: https://github.com/googlemaps/android-samples/tree/master/ApiDemos if you want to grant the permission on API 23(Android M) at the running time.