title: GPS Locater error on Android phone
body: <p>I've created an application in which, when I click a button, it gives me my gps coordinates. In the simulator it works with no problem, but when I've tried it on a mobile phone a had the next 2 scenarios: when I had the GPS activated, nothing happened, and when i didn't had the GPS connected, it said "Gps Disabled"</p>
  
  <p>Here is my code so far:
  This is the .java file: (Saver.java):</p>
  
  <pre><code>package com.example.lifesaver;
  
  import android.location.Location;
  import android.location.LocationListener;
  import android.location.LocationManager;
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Context;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.Toast;
  
  public class Saver extends Activity {
  
  Button b;
  
  Location newLocation = null;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_saver);
  b = (Button) findViewById(R.id.button1);
  
  
  // We use LocationManager class to obtain GPS locations
  LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  LocationListener mlocListener = new MyLocationListener();
  
  mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
  
  
  b.setOnClickListener(new OnClickListener(){
    public void onClick(View v)
    {
        if (newLocation != null) {
  
            String Text = "Current location is: " + "Latitud = "
                    + newLocation.getLatitude() + "Longitud = "
                    + newLocation.getLongitude();
            Toast.makeText(getApplicationContext(), Text,
                    Toast.LENGTH_SHORT).show();
        }
    }
  }); 
  }
  
  //MyLocationListener class
  
  public class MyLocationListener implements LocationListener
  {
  
      public void onLocationChanged(Location loc)
      {
          newLocation = loc;
      }
  
      public void onProviderDisabled(String provider)
      {
          Toast.makeText(getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT).show();
      }
  
      public void onProviderEnabled(String provider)
      {
          Toast.makeText(getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();
      }
  
      public void onStatusChanged(String provider, int status, Bundle extras)
      {
      }
  }
  }
  </code></pre>
  
  <p>And the .xml file(activity_saver.xml):</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".Saver" &gt;
  
  &lt;Button
  android:id="@+id/button1"
  android:layout_width="60dp"
  android:layout_height="60dp"
  android:layout_centerHorizontal="true"
  android:layout_centerVertical="true"
  android:background="@drawable/circle" 
  android:onClick="onClick"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Also, i've added this in the AndroidManifest.xml file:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"&gt;
  &lt;/uses-permission&gt;
  </code></pre>