Невозможно дать разрешение на доступ к местоположению в веб-браузере Android - PullRequest
0 голосов
/ 07 ноября 2019

Я создал приложение для веб-просмотра проекта. Я хочу получить доступ к разрешению для местоположения (ACCES_FINE_LOCATION) в Android Это мой код Java:

super.onCreate(savedInstanceState);
        try {
            this.getSupportActionBar().hide();
        } catch (NullPointerException e) {
        }
        setContentView(R.layout.activity_main);

        mWebView = (WebView) findViewById(R.id.webView1);
        mWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onGeolocationPermissionsShowPrompt(final String origin,
                                                           final GeolocationPermissions.Callback callback) {


                final boolean remember = false;
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("Locations");
                builder.setMessage("Would like to use your Current Location ")
                        .setCancelable(true).setPositiveButton("Allow", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {                    // origin, allow, remember
                        callback.invoke(origin, true, remember);
                    }
                }).setNegativeButton("Don't Allow", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {// origin, allow, remember
                        callback.invoke(origin, false, remember);
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            }


        });
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);

        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                view.loadUrl(url);
                return true;

            }
        });


        webSettings.setJavaScriptEnabled(true);
        webSettings.setGeolocationEnabled(true);
        mWebView.getSettings().setAppCacheEnabled(true);
        mWebView.getSettings().setDatabaseEnabled(true);
        mWebView.getSettings().setDomStorageEnabled(true);
        mWebView.getSettings().setGeolocationDatabasePath(getFilesDir().getPath());


        mWebView.loadUrl("https://church-map-site.herokuapp.com/");

В моем файле App.js у меня есть этот код:

navigator.geolocation.getCurrentPosition(positions => {
      let lat, lon;
      /*
      setLat(positions.coords.latitude);
      setLon(positions.coords.longitude);
      */
      lat = positions.coords.latitude;
      lon = positions.coords.longitude;
      setLocatie({
        lat: lat,
        lon: lon
      })
      fetch(`${url}/locatii/${lat}/${lon}`)
        .then(res => res.json())
        .then(data => {
          setData(data);
          //console.log(data)
        })
        .catch(err => console.log(err))
    }, err => alert("eroare", err));

Когда язапущенное приложение показывает мне это: alow image

Когда я нажимаю на alow, отображается предупреждение об обработке ошибок из навигатора error image В manifest.xmlЯ написал разрешение на местоположение доступа <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> Что я пропустил?

...