Here are the steps:
Step 1: Create services running in background.
Step 2: You require following permission in Manifest file too:
android.permission.ACCESS_FINE_LOCATION
Step 3: Write code:
final LocationManager manager = (LocationManager)context.getSystemService (Context.LOCATION_SERVICE );
if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) )
Toast.makeText(context, "GPS is disabled!", Toast.LENGTH_LONG).show();
else
Toast.makeText(context, "GPS is enabled!", Toast.LENGTH_LONG).show();
Step 4: Or simply you can check using:
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
Step 5: Run your services continuously to monitor connection.