Location request issues

1

Hello, good afternoon! I'm having problems with the return of my location in my code (it's also not asking the user for permission)

ACTIVITY CODE

public class GPSActivity extends AppCompatActivity implements LocationListener {
private TextView tv_gpsTexto;
private LocationManager locationManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gps);
    SetToolbar();

    tv_gpsTexto = (TextView) findViewById(R.id.tv_gpsTexto);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    boolean isGPSEnabled = locationManager
            .isProviderEnabled(LocationManager.GPS_PROVIDER);

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    //Teste  para permissão
    if ((ContextCompat.checkSelfPermission(GPSActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)
            && (ContextCompat.checkSelfPermission(GPSActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)){

        //Requisição da permissão no celular (você vai dar acesso)
        ActivityCompat.requestPermissions(GPSActivity.this,
                new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 100);

        //Envia a localização para a plataforma
        Location location = locationManager.getLastKnownLocation(locationManager.NETWORK_PROVIDER);
        onLocationChanged(location);
        return;
    }

}

@Override
public void onLocationChanged(Location location) {
    //Pegar Latitude e Longitude
    Log.d("TagPermissao3", "O USUÁRIO MUDOU A LOCALIZACAO");
    double longitude = location.getLongitude();
    double latitude = location.getLatitude();

    tv_gpsTexto.setText("Logitude: " + longitude + "\n" + "Latitude: " + latitude);
}

private void SetToolbar() {
    TextView tite;
    tite = (TextView) findViewById(R.id.tite);
    tite.setTypeface(GetFont.BoldFont(this));
    tite.setText("GPS");
    ImageView reply = (ImageView) findViewById(R.id.reply);
    reply.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();

        }
    });
}

}

And, I declared the following permissions in Manifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
asked by anonymous 20.12.2018 / 17:14

0 answers