I'm currently writing an app in Android that works with the GPS. At the moment I'm able to work out whether the GPS is enabled. My problem is that I want to enable the GPS on app startup if it is disabled. How can I do this programmaticaly?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
You can't, starting with Android 1.5. The most you can do is pop open the activity to allow the user to toggle it on/off. Use the action held in
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
to craft an Intent to open this activity.First check whether the location service is already on or not ??
Checking location service is enabled or not
Then finally to open if location service in turned off previously
You might use the following:
but it will only work if you have system signature protection level. So you need to cook your own Image to actually use it :/
if your question is at the user level of android these properties are located in:
"Settings -> Location -> Use wireless networks" -> "Settings -> Location -> Use GPS satellites"
.But at the developer can use the class
"android.provider.Settings.Secure"
with the appropriate permissions.This method code can be help for you
You should use the Location Settings Dialog in Play Services that prompts the user to enable location services (if necessary) with just one click.