Android 关于Webview的一些问题

1.ERR_CLEARTEXT_NOT_PERMITTED
在这里插入图片描述
【解决】
在AndroidManifest.xml中添加

<!--权限请求__访问互联网-->
<uses-permission android:name="android.permission.INTERNET" />

<!--application中添加-->
android:usesCleartextTraffic="true"


<application
       
       android:usesCleartextTraffic="true"
      >
        <activity android:name=".MainActivity">
            <intent-filter>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
</application>

2.阻止location.href打开内置浏览器
【解决】

//activity中添加
//  WebView contentWebView  = (WebView) findViewById(R.id.mapwebview)
contentWebView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view,String url){
                return false;
            }
        });

3.localStorage.setItem()无效
【解决】

 	    contentWebView.getSettings().setDomStorageEnabled(true);
        contentWebView.getSettings().setAppCacheMaxSize(1024*1024*8);
        String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
        contentWebView.getSettings().setAppCachePath(appCachePath);
        contentWebView.getSettings().setAllowFileAccess(true);

        contentWebView.getSettings().setAppCacheEnabled(true);

4.全屏显示
【解决】

		Window window = getWindow();

        //定义全屏参数
        int flag=WindowManager.LayoutParams.FLAG_FULLSCREEN;
        //设置当前窗体为全屏显示
        window.setFlags(flag, flag);

猜你喜欢

转载自blog.csdn.net/weixin_42547014/article/details/106785980
今日推荐