真的应该弃用`shouldOverrideUrlLoading`吗?我可以用什么代替呢? [英] Is `shouldOverrideUrlLoading` really deprecated? What can I use instead?

查看:392
本文介绍了真的应该弃用`shouldOverrideUrlLoading`吗?我可以用什么代替呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"shouldOverrideUrlLoading"是否已被弃用?如果是这样,我该怎么用呢?

Is "shouldOverrideUrlLoading" really deprecated? If so, what can I use instead?

shouldOverrideUrlLoading似乎已弃用定位到Android N ,并且我需要使应用程序自API 19起一直运行到最新的Android N(测试版),我使用的某些功能是Android N的新功能(例如Data Saver),因此针对棉花糖将无济于事,因为我需要使用这些新功能,这是我使用的代码的一部分:

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:")) {
        ...
    }
    ...
}

这是Android Studio给我的消息:

And this is the message Android Studio gave me:

覆盖"android.webkit.WebViewClient"中不推荐使用的方法 该检查报告在指定的检查范围中使用了不赞成使用的代码.

Overrides deprecated method in 'android.webkit.WebViewClient' This inspection reports where deprecated code is used in the specified inspection scope.

我想知道从API 19开始直到最新的Android N Beta(以及发布时的最终版本),使用@SuppressWarnings("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?

推荐答案

我认为我使用的版本是一个很好的版本,因为它与Android Developer Docs完全相同,除了字符串的名称,他们使用的是"view",我使用的是"webview",其余的一样

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

不,不是.

N Developer Preview的新功能具有以下方法签名:

The one that is new to the N Developer Preview has this method signature:

public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)

所有Android版本(包括N)都支持的方法具有以下方法签名:

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?

覆盖已弃用的参数,该参数以String作为第二个参数.

Override the deprecated one, the one that takes a String as the second parameter.

这篇关于真的应该弃用`shouldOverrideUrlLoading`吗?我可以用什么代替呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆