Turning on GPS in your Device without going to Settings

iamVariable
1 min readMay 16, 2019

Hey all!! Hope doing good:)

We can turn on GPS programmatically in two ways.

  1. redirecting the user to location settings of a device (by code)
  2. 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

--

--

iamVariable
iamVariable

Written by iamVariable

Experienced Mobile Application Developer skilled in the full software development lifecycle, including analysis, design, development, and deployment.