Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prompt user to enable GPS_PROVIDER and/or NETWORK_PROVIDER?

Tags:

android

I need to get location of user. I put in manifest

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

How to prompt user to enable GPS_PROVIDER and/or NETWORK_PROVIDER ?

like image 996
Damir Avatar asked Oct 10 '11 13:10

Damir


People also ask

How do you check if Location services are enabled?

Settings > Location > Mode > Battery Saving . This mode only uses WiFi, Bluetooth or mobile data instead of GPS to determine the user location. That's why you have to check if the network provider is enabled and locationManager.

How do I ask to turn on Location on Android?

The, after opening the Trip Advisor app, and tapping the Near me now option, I'm prompted with the second image, where I'm asked to Turn on Location services. After I tap the button, a dialog shows up so I can allow, or disallow, the Location service to be turned on.

How do you check if Location is turned off?

Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.


2 Answers

You can start an options intent for the location settings.

Intent gpsOptionsIntent = new Intent(       android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);   startActivity(gpsOptionsIntent); 
like image 82
Franziskus Karsunke Avatar answered Oct 07 '22 06:10

Franziskus Karsunke


LOCATION_MODE will be LOCATION_MODE_OFF if GPS is off, which will return value 0.

int off = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE);     if(off==0){         Intent onGPS = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);         startActivity(onGPS);     } 
like image 39
Saurabh Pakhare Avatar answered Oct 07 '22 06:10

Saurabh Pakhare