android6.0下webview的定位权限设置

WebView webView = (WebView)findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();

//webview支持js脚本
webSettings.setJavaScriptEnabled(true);

//启用数据库  
webSettings.setDatabaseEnabled(true);    

//设置定位的数据库路径  
String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); 
webSettings.setGeolocationDatabasePath(dir);   

//启用地理定位
webSettings.setGeolocationEnabled(true);  

//开启DomStorage缓存
webSettings.setDomStorageEnabled(true)  

//配置权限
webView.setWebChromeClient(new WebChromeClient() {
  @Override
  public void onReceivedIcon(WebView view, Bitmap icon) {
     super.onReceivedIcon(view, icon);

}

@Override
public void onGeolocationPermissionsShowPrompt(String origin,Callback callback) {
  callback.invoke(origin, true, false);  
  super.onGeolocationPermissionsShowPrompt(origin, callback);

}
});

//在Androidmanifest.xml中开启权限

 

Android6.0版本需要加上:

            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", "弹出提示");
                }
            }


你可能感兴趣的:(移动)