In my application, How can I detect when GPS is turn on by other application installed on device?
2 Answers
You can easily check what app is able to get a location data by reading apps permissions with PackageManager class.
http://developer.android.com/reference/android/content/pm/PackageManager.html
- 12,020
- 7
- 39
- 58
steps -
- Create services running in backgroud
You require following permission in Manifest file too -
android.permission.ACCESS_FINE_LOCATION
write code
final LocationManager manager = (LocationManager)context.getSystemService (Context.LOCATION_SERVICE );
if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) Toast.makeText(context, "GPS is disable!", Toast.LENGTH_LONG).show(); else Toast.makeText(context, "GPS is Enable!", Toast.LENGTH_LONG).show();
Or simply you can check
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE ); boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
run your services continuous to monitor connection
- 2,552
- 28
- 27