Home Android Checking GPS Status

Checking GPS Status

The application I’m currently working requires that the user has the GPS active on phone. otherwise application is useless. The application needs the Geodata to function. This brought up the issue of, how do we know if the user actually has the GPS enabled on the phone? If they don’t, the application will still work, but all values are zero. to avoid this we need to check GPS status.

This can be done by using locationManager. it has isProviderEnabled() method by using that we can check GPS status.

Here is code snippet.

protected void onCreate(Bundle savedInstanceState) {
     LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);

     if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){

private void createGpsDisabledAlert(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Your GPS is disabled! Would you like to enable it?")
     .setPositiveButton("Enable GPS",
          new DialogInterface.OnClickListener(){
          public void onClick(DialogInterface dialog, int id){
     .setNegativeButton("Do nothing",
          new DialogInterface.OnClickListener(){
          public void onClick(DialogInterface dialog, int id){
AlertDialog alert = builder.create();;

private void showGpsOptions(){
		Intent gpsOptionsIntent = new Intent(

And thats it! When the user starts the activity, if the GPS is off, the dialog will pop up asking them what they want to do. If the GPS is already on, nothing will happen.

 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
1 Comment  comments 

One Response

  1. Bhagyashree

    Hey…Quite informative blogs about GPS.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>