Я вроде как заблокирован здесь с некоторых дней.
Моя страница настроек продолжает перезагружаться после вызова из моего
Android-приложение.
Мое приложение для Android проверяет обновления местоположения на регулярной основе.
В моих настройках я должен откалибровать его на «Высокая точность» после включения кнопки LOCATION.
//
//
//
locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);
listener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
setLattitude(location.getLatitude());
setLongitude(location.getLongitude());
getAllLocations();
}
@Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
@Override
public void onProviderEnabled(String s) {
}
@Override
public void onProviderDisabled(String s) {
Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(i);
}
};
// this code won't execute IF permissions are not allowed, because in the line above there is return statement.
if (Build.VERSION.SDK_INT < 23) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
Toast.makeText(getApplicationContext(),
"111111",
Toast.LENGTH_LONG).show();
locationManager.requestLocationUpdates(NETWORK_PROVIDER, 5000, 0, listener);
return;
}
locationManager.requestLocationUpdates(NETWORK_PROVIDER, 5000, 0, listener);
Toast.makeText(getApplicationContext(),
"222222",
Toast.LENGTH_LONG).show();
}else{
//noinspection MissingPermission
if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission
(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
Toast.makeText(getApplicationContext(),
"333333",
Toast.LENGTH_LONG).show();
ActivityCompat.requestPermissions((Activity) context, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 1);
//ActivityCompat.requestPermissions((Activity) context, new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
return;
}
else{
locationManager.requestLocationUpdates(NETWORK_PROVIDER, 0, 0, listener);
Toast.makeText(getApplicationContext(),
"444444",
Toast.LENGTH_LONG).show();
}
}
Тогда мой по запросу
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults){
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
//locationManager.requestLocationUpdates(NETWORK_PROVIDER, 0, 0, listener);
if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED){
locationManager.requestLocationUpdates(NETWORK_PROVIDER, 0, 0, listener);
}
/*
if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
== PackageManager.PERMISSION_GRANTED){
locationManager.requestLocationUpdates(NETWORK_PROVIDER, 0, 0, listener);
}
*/
}
}