How do I ask the user to allow access to the device's location? I'm programming in java and using the Android Studio IDE, and I'm extending to FragmentsActivity
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private static final int PERMISSION_ACCESS_COARSE_LOCATION = 0; private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
final Intent QuestionarioSegurancaActivity = new Intent(this, ActiveQuestionarioSeguranca2Activity.class);
Button button_Localizacao = (Button) findViewById(R.id.button_questionario_enviar_localizacao);
Button button_voltar_mapas = (Button) findViewById(R.id.button_maps_voltar);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
button_EnviarLocalizacao.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view) {
startActivity(QuestionarioSegurancaActivity);
}
});
}
/** * Manipulates the map once available. * This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
} else { }
}
}
}
This is the code I have, I wanted to create a method to require permission to access the user's location, but I do not find material about that class