I would like to detect when the user changes the GPS settings on or off for an Android phone. Meaning when user switches GPS sattelite on/off or detection via access points etc.
Add a TextView and a Button in the layout file. The TextView will display if the GPS is enabled or disabled upon the Button trigger.
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.
To minimize battery usage, the Android system automatically disables some features such as the GPS when the power is low or battery saving mode is turned on. To be able to use your GPS effectively again, turning off battery saver could help you out.
As I have found out the best way to do this is to attach to the
<action android:name="android.location.PROVIDERS_CHANGED" />
intent.
For instance:
<receiver android:name=".gps.GpsLocationReceiver"> <intent-filter> <action android:name="android.location.PROVIDERS_CHANGED" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver>
And then in the code:
public class GpsLocationReceiver extends BroadcastReceiver implements LocationListener ... @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().matches("android.location.PROVIDERS_CHANGED")) { // react on GPS provider change action } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With