Turning on GPS in your Device without going to Settings
Hey all!! Hope doing good:)
We can turn on GPS programmatically in two ways.
- redirecting the user to location settings of a device (by code)
- another way is to ask to turn on GPS by GPS dialog using LocationSettingsRequest and SettingsClient.
The first way, Android Intent providing us Settings.ACTION_LOCATION_SOURCE_SETTINGS
The another way is as I said earlier using LocationSettingsRequest.
For that I created a library to make it simple.
implementation 'com.github.MuthuHere:EnableGPS:1.0.0'
Simple build this light weighted library.
Implement callback interfaceEnableMyGps.GpsStatusCallBack
into your activity. It will give you two override methods, onGpsSettingStatus
with a boolean and onGpsAlertCanceledByUser.
To initialise
val gpsStatus = EnableMyGps(this)
To check the status
gpsStatus.checkMyGpsStatus()
it will return you a boolean True if GPS enabled, False if not.
Use as per your required:)
Thats better!.
Source code https://github.com/MuthuHere/EnableGPS