Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set the location permission of webview in android

Shulou Source: shulou.com Published: 2022-05-31 21:07:12 09月21日 Update

In this article, the editor introduces in detail "how to set the location permission of webview in android". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to set the location permission of webview in android" can help you solve your doubts.

As follows:

WebView webView = (WebView) findViewById (R.id.webview); WebSettings webSettings = webView.getSettings (); / / webview supports js script webSettings.setJavaScriptEnabled (true); / / enables database webSettings.setDatabaseEnabled (true); / / sets the database path String dir = this.getApplicationContext (). GetDir ("database", Context.MODE_PRIVATE). GetPath (); webSettings.setGeolocationDatabasePath (dir); / / enable geolocation webSettings.setGeolocationEnabled (true) / / enable DomStorage cache webSettings.setDomStorageEnabled (true) / / configure permissions webView.setWebChromeClient (new WebChromeClient () {@ Overridepublic void onReceivedIcon (WebView view, Bitmap icon) {super.onReceivedIcon (view, icon);} @ Overridepublic void onGeolocationPermissionsShowPrompt (String origin,Callback callback) {callback.invoke (origin, true, false); super.onGeolocationPermissionsShowPrompt (origin, callback);}}); / / enable permissions in Androidmanifest.xml

The Android6.0 version needs to be added:

If (Build.VERSION.SDK_INT > = 23) {int checkPermission = ContextCompat.checkSelfPermission (MainActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION); if (checkPermission! = PackageManager.PERMISSION_GRANTED) {ActivityCompat.requestPermissions (MainActivity.this, new String [] {Manifest.permission.ACCESS_COARSE_LOCATION}, 1); ActivityCompat.requestPermissions (MainActivity.this, new String [] {Manifest.permission.ACCESS_FINE_LOCATION}, 1); Log.d ("TTTT", "pop-up prompt") }} here, the article "how to set the location permission of webview in android" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.

Tags: Permissions location central settings articles content data databases appropriateness geography ideas new knowledge more steps versions knowledge knowledge points articles details cache scripts Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Apple Shulou Information Huawei vpn