- Posts no fórum: 7
21/06/2018, 18:52:33 via Web
21/06/2018 18:52:33 via Web
Como eu faço para pedir para o usuário permitir acesso a localização do dispositivo.estou progamando em java e usando a IDE do Android studio ,e estou extendendo a FaragmentsActivity
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 {
}
}
}
esse é o código que eu tenho ,queria criar um método para requerer permissão para acesso a localização do usuário ,porrem não encontro material sobre essa classe
Conteúdo editorial recomendado
Com o seu consentimento, o conteúdo externo é carregado aqui.
Ao clicar no botão acima, concorda que o conteúdo externo poderá ser-lhe exibido. Os dados pessoais podem ser transmitidos a fornecedores terceiros no processo. Pode encontrar mais informações sobre isto no nosso Política de Privacidade.