gpt4 book ai didi

未调用 Android webview shouldOverrideUrlLoading 方法

转载 作者:行者123 更新时间:2023-11-29 14:13:17 40 4
gpt4 key购买 nike

Android webview 的 shouldOverrideUrlLoading 方法不会调用具有 pdf 文件的链接的 onclick

代码:

public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url.endsWith(".pdf")) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
return true;
} else {
view.loadUrl(url);
}

return true;
}

最佳答案

试试这个

private class WebClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// check here the url
if (url.endsWith(".pdf")) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
} else {
super.onPageStarted(view, url, favicon);
}
}

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

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

关于未调用 Android webview shouldOverrideUrlLoading 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40420071/

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