gpt4 book ai didi

android - 在 API 18 中使用什么来代替 getUrl()

转载 作者:行者123 更新时间:2023-12-02 04:31:44 25 4
gpt4 key购买 nike

我正在使用 API 级别 18 表单显示同一 Activity 中的网页,但它给出了错误:getURL() required API 21 .
我可以用什么来代替这个?

这是代码:

@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(request.getUrl().toString());
return false;
}

最佳答案

尝试这个

private void LoadUrlWebView( String url_api ) {
try {
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.getSettings().setAllowContentAccess(true);
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Log.i( "","setWebViewClient::shouldOverrideUrlLoading::url: "+url);
webView.loadUrl(url);
CookieManager.getInstance().setAcceptCookie(true);
return true;
//return super.shouldOverrideUrlLoading(view, request);
}

@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.i( "setWebViewClient::onPageFinished::url: ", url);
}
});
webView.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
try {
progressBar.setProgress(newProgress);
if ( newProgress < 100 && progressBar.getVisibility()==ProgressBar.GONE) {
progressBar.setVisibility(ProgressBar.VISIBLE);
}
if (newProgress == 100) {
progressBar.setVisibility(ProgressBar.GONE);
}
}catch (Exception e){
Log.i( "onProgressChanged", e);
}
}

@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
setTitle( title );
Tools.LogCat("setWebChromeClient::onReceivedTitle:: getUrl:"+ view.getUrl() + "\ntitle:"+title );
}
});

webView.loadUrl(view.getUrl());
} catch (Exception e) {
Tools.LogCat(this, "setUpNavigationView", e);
}
}

关于android - 在 API 18 中使用什么来代替 getUrl(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48034618/

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