Calling system settings from an Android app - GPS example
|
This tutorial shows how to redirect the user to a system settings screen asking to modify some settings the application depends on. We will make a specific example with GPS: The application can be used only if GPS is available.
The android systems GPS setting screen can be called just like any other Activities: |
|
- startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTING
S), 0);
To check GPS availability use the code code below: (the Activity must implement LocationListener)
- LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L,1.0f, this);
- boolean isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);
The example application will do the following:
1. On application start check if gps is available. If it is on the application can proceed.
2. If GPS is turned off, display a dialog asking the user to turn it on, and 2 buttons, one to go to GPS settings screen, and a cancel button to exit the application.
3. When the dialog is displayed we must store in a variable that the user was already asked once to turn on GPS
4. If the user leaves to the GPS options screen, it is not sure that he will turn on the GPS!
5. When the user returns to uor application we recheck the GPS. If its available we can proceed, otherwise we close the application. (in order to check that it is a returm to the activity or is it its first start we check the variable we set in step 3)
So we will have the code in the applications starting Activitys onResume method, where we will detect GPS availability, use a dilaog to ask the user, an Intent to go to options screen, and a variable to indicate the state of the GPS turn on process. The code for this example application is available here. Turn off yuor GPS and try runing it.
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@StephanieNich10 (Stephanie Nichols)#android I laughed so hard at ochocinco 's avi. Hahahaha http://t.co/MPuhhi3m
25 weeks 3 days ago -
@CarlaAtkins8 (Carla Atkins)#android Omg! This is actually f'n interesting http://t.co/JodMOehr
25 weeks 3 days ago -
@MarianMcleod12 (Marian Mcleod)#android Precisely what song is? http://t.co/YmJXU0rB
25 weeks 3 days ago -
@JoBeach15 (Jo Beach)#android haha this made me laugh, i love ted:-) http://t.co/gtcWQ79C
25 weeks 3 days ago -
@aochart3 (青ちゃ)Start playing Paradise Island on Android http://t.co/DEID0Ao5 #Android #Androidgames #Gameinsight http://t.co/e1bifSeL
25 weeks 3 days ago
Poll
Useful resources
Android Development Projects
- Youtube flash video launch from website opened in Android webview by vijayknarang
- android app task done by mamun00001
- Android enhancement by mobileapps07
- Android App for USB webcam video recording by blink311
- Electronics Product Prototype with Andriod & Iphone Interface by IntelliFreelance
- We need an Android Programmer! - repost by forple2013
- Android app for self-serve kiosk by maxish
- Learning App Conversion by VRayGuide
- i need app for my SE x10mini that can record voice call. by reynatoserato
- Ios Project - repost by emmibey



