Android GPS on or off

Is there a way to check if Android GPS is turned on or off without any permission, just a state that I don't need to switch.

thanks

+6
android state android-manifest toggle gps
source share
3 answers

Not. Android status required to check GPS status

android.permission.ACCESS_FINE_LOCATION 

GPS Status Check Code

 LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE ); boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
+27
source share

steps -

  • Creating services running in backgroud
  • You also need the following permission in the manifest file -

     android.permission.ACCESS_FINE_LOCATION 
  • write code

      final LocationManager manager = (LocationManager)context.getSystemService (Context.LOCATION_SERVICE ); if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) //what you want to do else //what you want to do 
  • Or just you can check

     LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE ); boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER); 
  • constantly run services to monitor the connection

  • calling your services from Activity
+5
source share

If you want to check the GPS status that it is on or off, this solution will help you

 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(); 
+2
source share

All Articles