我对地理位置许可问题有疑问,因为我是分段请求的,但是我想按ACCEPT键将我带到一个网站,但如果没有问题,我将带我到另一个网站,但是没有纬度和长度,因为否则会引发错误,但显然不会接受命令。同样,接受或拒绝许可证的标志是我第一次进行咨询时出现的,然后再也没有问过我(就像我选择放弃该选项一样)。我将完整的代码传递给。 [更新]
public void onCreate(Bundle savedInstanceState) {
double longitud = 0.0 ; latitud = 0.0;
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
if (checkSelfPermission(getContext(),
android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(getContext(),
android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getActivity(),
new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION},
99);
} else {
locationStart();
}
}
private void locationStart() {
Log.e("ya viene","ingresa a locationStar");
LocationManager mlocManager = (LocationManager) requireContext().getSystemService(Context.LOCATION_SERVICE);
Localizacion Local = new Localizacion();
Local.setMainActivity(this);
assert mlocManager != null;
final boolean gpsEnabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!gpsEnabled) {
Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(settingsIntent);
Log.e("ya viene","ingresa a !gpsEnabled");
}
// requestPermissions(new String[]{
// Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_REQ_CODE)
//
// ActivityCompat.requestPermissions(getActivity(), new String[]{
// Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_REQ_CODE);
if (checkSelfPermission(getContext(),
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
checkSelfPermission(getContext(),
android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(getActivity(),
new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION},
99);
return;
} else{
Log.e("DB", "PERMISSION GRANTED");
}
toast = Toast.makeText(Objects.requireNonNull(getContext()).getApplicationContext(),
"Por favor aguarde, ésto puede demorar unos segundos...",Toast.LENGTH_LONG);
toast.show();
progressDialog = new ProgressDialog(requireContext());
progressDialog.show();
progressDialog.setContentView(R.layout.progressbar);
progressDialog.setCancelable(false);
Objects.requireNonNull(progressDialog.getWindow()).setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,MIN_DISTANCE_CHANGE_FOR_UPDATES,MIN_TIME_BW_UPDATES, (LocationListener) Local);
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MIN_DISTANCE_CHANGE_FOR_UPDATES,MIN_TIME_BW_UPDATES,(LocationListener) Local);
}
private void requestPermissions(FragmentActivity activity,String[] strings,int i) {
Log.e("ya viene","ingresa a RequestPermissionsResult");
// if (requestCode == 99) {
//
// if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// locationStart();
// return;
// }else
// {
// Cargarwebview(0.0, 0.0);
// }
// }
}
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
}
//LLAMA AL SERVIDOR PARA CARGAR EL WEB VIEW
@SuppressLint("SetJavaScriptEnabled")
private void Cargarwebview(double latitud,double longitud) throws MalformedURLException {
Log.e("ya viene","ingresa a CargarWebView");
final WebView webView = Objects.requireNonNull(getView()).findViewById(R.id.yaviene_webview);
ImageView imagen = Objects.requireNonNull(getView()).findViewById(R.id.imagen_principal);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(false);
webView.clearCache(true);
webView.setWebChromeClient(new WebChromeClient());
webView.reload();
toast = Toast.makeText(Objects.requireNonNull(getContext()).getApplicationContext(),
"Su consulta está terminado de ser procesada", Toast.LENGTH_LONG);
toast.show();
webView.loadUrl("http://www.yaviene.com/usuariocontrol/urbano.php?a="+getString(R.string.NumeroE)+"&v=1&lat="+latitud+"&Lng="+longitud);
webView.setWebViewClient(new WebViewClient() {
@Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webView.loadUrl("file:///android_asset/erroryaviene.html");
} });
Log.e("ya viene","http://www.yaviene.com/usuariocontrol/urbano.php?a="+getString(R.string.NumeroE)+"&v=1&lat="+latitud+"&Lng="+longitud);
progressDialog.dismiss();
imagen.setVisibility(View.GONE);
}
public void setLocation(Location loc) {
//Obtener la direccion de la calle a partir de la latitud y la longitud
if (loc.getLatitude() != 0.0 && loc.getLongitude() != 0.0) {
try {
Geocoder geocoder = new Geocoder(getContext(), Locale.getDefault());
// List<Address> list = geocoder.getFromLocation(
List<Address> list = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1); //ESTO TRAE LA DIRECCIÓN CON ALTURA, CALLE, LOCALIDAD, PAIS
/* if (!list.isEmpty()) {
Address DirCalle = list.get(0);
mensaje2.setText("Mi direccion es: \n"
+ DirCalle.getAddressLine(0));
}*/
Log.e("ya viene","Esto trae Geocoder"+ list);
Log.e("ya viene","Esta es la latitud: "+ loc.getLatitude()+" y esta es tu longitud "+loc.getLongitude());
} catch (IOException e) {
e.printStackTrace();
}
}
}