GPS plugged in but does not work in APP anymore

0

Okay? Next, I am implementing a GPS code in my APP. It was working normally until then, until the time I tested turn off the GPS of the phone - to see if it gave error in the same APP. But when I activated the GPS of the cell phone again, it is as if my application no longer recognizes GPS.

For all intents and purposes, follow my code:

MainActivity.java file:

public class MainActivity extends AppCompatActivity {

    private TextView txtLatitude, txtLongitude;
    private String latitude, longitude;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txtLatitude = (TextView) findViewById(R.id.txtLat);
        txtLongitude = (TextView) findViewById(R.id.txtLong);

        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 124);

        GPSTracker g = new GPSTracker(getApplicationContext());
        Location l = g.getLocation();

        if(l != null){

            double lat = l.getLatitude();
            double lon = l.getLongitude();

            if(latitude == null && longitude == null) {

                latitude = String.format("%.8f", lat) + "\n";
                longitude = String.format("%.8f", lon) + "\n";

            }else{

                latitude = latitude + String.format("%.8f", lat) + "\n";
                longitude = longitude + String.format("%.8f", lon) + "\n";

            }

            txtLatitude.setText(latitude);
            txtLongitude.setText(longitude);

        }else{

            Toast.makeText(getApplicationContext(), "Erro na captura!", Toast.LENGTH_SHORT).show();

        }

    }

}

Remembering that in my AndroidManifest.xml I have right permission set:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

I'm counting on someone's help, please.

Thank you !!! : -)

    
asked by anonymous 01.08.2017 / 02:00

0 answers