1.权限问题:在配置文件中需要设置网络权限
<uses-permission android:name="android.permission.INTERNET" />
2.基本配置问题
.settings.setSupportZoom(false);// 用于设置webview放大
.settings.setBuiltInZoomControls(false);
解决方法:启动webview的html5的本地存储功能。webview.getSettings().setDomStorageEnabled(true); webview.getSettings().setAppCacheMaxSize(1024*1024*8); String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath(); webview.getSettings().setAppCachePath(appCachePath); webview.getSettings().setAllowFileAccess(true); webview.getSettings().setAppCacheEnabled(true);
4.调用getDeviceID 方法的时候,js没有加载完毕,导致出现空白
解决办法:
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
//在这里执行你想调用的js函数
if(!flag_get_deviceid){
load();
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
public void load(){
String key="";
String androidID="";
try{
androidID = Secure.getString(getContentResolver(),Secure.ANDROID_ID);
Log.d(TAG, "androidID:"+androidID);}catch(Exception e){
Log.e(TAG, "");
}finally{
String script=String.format("javascript:getDeviceID('"+androidID+"')");
webActDetail.evaluateJavascript(script, new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Log.d(TAG, "onReceiveValue value=" + value);
if(value!=null){
flag_get_deviceid=true;
}
}});
}
}
5.android手机版本问题,现在H5界面实现多样化,导致很多H5界面在低版本的机型上无法展示或者样式错乱