gpt4 book ai didi

android - WebView 不加载某些页面

转载 作者:行者123 更新时间:2023-11-29 15:37:10 25 4
gpt4 key购买 nike

无法在 WebView 中加载以下网页

https://6awlanow.com/about/faqs

到目前为止已尝试关注 -

    webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setUserAgentString("Android WebView");
webView.setWebViewClient(new WebViewClient() {

@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().getPath());
//if (progressDialog != null && progressDialog.isShowing()) {
// progressDialog.dismiss();
//}
return true;
}

//If you will not use this method url links are opeen in new brower not in webview
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}

//Show loader on url load
@Override
public void onLoadResource(WebView view, String url) {
}
@Override
public void onPageFinished(WebView view, String url) {
try {
//if (progressDialog.isShowing()) {
// progressDialog.dismiss();
//}
} catch (Exception exception) {
exception.printStackTrace();
}
}

@Override
public void onReceivedError(
WebView view, WebResourceRequest request, WebResourceError error
) {
//progressDialog.dismiss();
super.onReceivedError(view, request, error);
}

});

我已经提供了互联网权限。 URL 在任何地方都可以正常加载,但 WebView 除外。我收到以下错误 -

在我的控制台上获取以下信息 -

I: [INFO:CONSOLE(31)] "Uncaught TypeError: Object.assign is not a function", source: https://6awlanow.com/app.c98a13d5a9fdd32775ca.js (31)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)
I: [INFO:CONSOLE(0)] "Error: Invalid negative value for <rect> attribute ry="-.125"", source: https://6awlanow.com/about/faqs (0)

最佳答案

使用下面的代码,它应该可以工作,我测试过它可以工作。

public class WebViewEx extends AppCompatActivity {

private WebView webView;
private ProgressDialog progDailog;
Activity activity;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view_ex);

webView = findViewById(R.id.webView);
activity = this;

progDailog = ProgressDialog.show(activity, "Loading", "Please wait...", true);
progDailog.setCancelable(false);


webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient() {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
progDailog.show();
view.loadUrl(url);

return true;
}

@Override
public void onPageFinished(WebView view, final String url) {
progDailog.dismiss();
}
});

webView.loadUrl("https://6awlanow.com/about/faqs");
}
}

您的 XML 将如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>

下面是我在WebView中得到的结果:

enter image description here

我希望这能解决您的问题,如果您有任何疑问,请告诉我。

关于android - WebView 不加载某些页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47372983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com