android 6.0下webview的定位权限设置 android 6.0下webview的定位权限设置方法
大强快跑 人气:19如下所示:
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中开启权限 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
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", "弹出提示"); } }
以上这篇android 6.0下webview的定位权限设置方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
加载全部内容