The WebView cannot be located.
I encountered a problem that cannot be located in WebView. I was unable to locate the problem when using webview. I found someone said they would do this.
WebSettings settings = wbContent.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setGeolocationEnabled(true); settings.setDomStorageEnabled(true); settings.setDatabaseEnabled(true); String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); settings.setGeolocationDatabasePath(dir); webChromeClient = new WebChromeClient(){ @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, true); super.onGeolocationPermissionsShowPrompt(origin, callback); } }; wbContent.setWebChromeClient(webChromeClient); wbContent.loadUrl("https://xxxxxxxxxxxxxxxxxxxxxxxx");
In many places on the internet, after this code is added, you can locate it normally. However, after I add it, there is still no use. No way, Baidu is not powerful to Google.
I read the log and said that I didn't get the permission, but callback. invoke (origin, true, true) in the Code is an operation to get the positioning permission.
I thought about it and suddenly thought that I had to dynamically apply for permissions after 6.0.
Code for dynamically applying for Permissions
if (Build.VERSION.SDK_INT >= 23) { int checkPermission = ContextCompat.checkSelfPermission(LocationTestActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION); if (checkPermission != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(LocationTestActivity.this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 1); ActivityCompat.requestPermissions(LocationTestActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1); }else { wbContent.loadUrl("https://xxxxxxxxxxxxxxxxxxxxxxxx"); } }
In this way, you can get the Positioning Result normally. Some people may not know where to apply dynamically. In fact, this depends on your specific process, you can also apply when you jump to this page or when displaying the page.
Finally, the onGeolocationPermissionsShowPrompt method is called only once. It is called only for the first time, just like the dynamic permission application.