I'm developing an Android application and it has a functionality that while the application is running if user enable or disable GPS. I received the Broadcast and display the status on an activity using Interface.
GpsLocationReceiver
public class GpsLocationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Toast.makeText(context, "GPS Disabled", Toast.LENGTH_SHORT).show();
}
}
I registered this BroadcastReceiver in Manifest.xml
<receiver android:name=".GpsLocationReceiver">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>