`shouldOverrideUrlLoading` 真的被弃用了吗?我可以用什么代替? [英] Is `shouldOverrideUrlLoading` really deprecated? What can I use instead?
问题描述
shouldOverrideUrlLoading"真的被弃用了吗?如果是这样,我可以用什么代替?
似乎 shouldOverrideUrlLoading
已被弃用 针对 Android N,我需要让应用程序从 API 19 开始运行,直到现在最新的 Android N(测试版),我使用了 Android N 中的一些新功能(例如 Data Saver),因此针对 Marshmallow 将无助于解决此问题,因为我需要使用这些新功能,以下是我使用的代码部分:
public boolean shouldOverrideUrlLoading(WebView webview, String url) {if (url.startsWith("http:") || url.startsWith("https:")) {...} else if (url.startsWith("sms:")) {...}...}
这是 Android Studio 给我的信息:
<块引用>覆盖android.webkit.WebViewClient"中已弃用的方法此检查报告在指定检查范围内使用弃用代码的情况.
我想知道使用 @SuppressWarnings("deprecation")
是否能让我在 API 19 之后的所有设备上工作,直到最新的 Android N Beta(以及发布时的最终版本),我不能自己测试,我从来没有用过,我需要确保它有效,所以,谁能告诉?
我认为我使用的版本是好的版本,因为它与 Android Developer Docs 完全相同,除了字符串的名称之外,他们使用view",我使用webview",其余部分是一样的
不,不是.
N 开发者预览版的新版本具有此方法签名:
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
包括N在内的所有Android版本都支持的方法签名:
public boolean shouldOverrideUrlLoading(WebView view, String url)
<块引用>
那我为什么要让它在所有版本上都能运行?
覆盖已弃用的,将 String
作为第二个参数的那个.
Is "shouldOverrideUrlLoading" really deprecated? If so, what can I use instead?
It seems like shouldOverrideUrlLoading
is deprecated targeting Android N and I need to make an app work since API 19 until the latest right now which is Android N (beta), I use some features that are new in Android N (like Data Saver), so targeting Marshmallow will not help with the issue since I need to use those new features, here is the part of the code I use:
public boolean shouldOverrideUrlLoading(WebView webview, String url) {
if (url.startsWith("http:") || url.startsWith("https:")) {
...
} else if (url.startsWith("sms:")) {
...
}
...
}
And this is the message Android Studio gave me:
Overrides deprecated method in 'android.webkit.WebViewClient' This inspection reports where deprecated code is used in the specified inspection scope.
Google says nothing about that deprecation.
I wonder if using @SuppressWarnings("deprecation")
will let me work on all devices since the API 19 until the latest Android N Beta (and its final version when it gets released), I can't test it myself, I never used that and I need to be sure that it works, so, anyone can tell?
The version I'm using I think is the good one, since is the exact same as the Android Developer Docs, except for the name of the string, they used "view" and I used "webview", for the rest is the same
No, it is not.
The one that is new to the N Developer Preview has this method signature:
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
The one that is supported by all Android versions, including N, has this method signature:
public boolean shouldOverrideUrlLoading(WebView view, String url)
So why should I do to make it work on all versions?
Override the deprecated one, the one that takes a String
as the second parameter.
这篇关于`shouldOverrideUrlLoading` 真的被弃用了吗?我可以用什么代替?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!