Skip to content

Commit 7aca7e5

Browse files
mvanbeusekomEgor
authored andcommitted
[url_launcher] Suppress deprecation warning in WebViewActivity (flutter#3008)
The url_launcher overrides the deprecated shouldOverrideUrlLoading(WebView view, String url) method to be backwards compatible with versions before Android API 24. This however currently displays the warning "WebViewActivity.java uses or overrides a deprecated API." when building for Android. This is causing some problems for developers who treat these warnings as errors as part of their build configuration. This PR addresses this issue by annotating the shouldOverrideUrlLoading(WebView view, String url) method with the @SuppressWarnings("deprecation") attribute. This PR also adds the @RequiresApi(Build.VERSION_CODES.N) annotation to the shouldOverrideUrlLoading(WebView view, WebResourceRequest request) method, which gives the Android/ Java tooling an indication this method should only by used from API 24 and higher.
1 parent 31aaec7 commit 7aca7e5

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

packages/url_launcher/url_launcher/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 5.5.3
2+
3+
* Suppress deprecation warning on the `shouldOverrideUrlLoading` method on Android.
4+
15
## 5.5.2
26

37
* Depend explicitly on the `platform_interface` package that adds the `webOnlyWindowName` parameter.

packages/url_launcher/url_launcher/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.webkit.WebResourceRequest;
1313
import android.webkit.WebView;
1414
import android.webkit.WebViewClient;
15+
import androidx.annotation.RequiresApi;
1516
import java.util.HashMap;
1617
import java.util.Map;
1718

@@ -38,6 +39,11 @@ public void onReceive(Context context, Intent intent) {
3839
private final WebViewClient webViewClient =
3940
new WebViewClient() {
4041

42+
/*
43+
* This method is deprecated in API 24. Still overridden to support
44+
* earlier Android versions.
45+
*/
46+
@SuppressWarnings("deprecation")
4147
@Override
4248
public boolean shouldOverrideUrlLoading(WebView view, String url) {
4349
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
@@ -47,6 +53,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
4753
return super.shouldOverrideUrlLoading(view, url);
4854
}
4955

56+
@RequiresApi(Build.VERSION_CODES.N)
5057
@Override
5158
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
5259
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

packages/url_launcher/url_launcher/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: url_launcher
22
description: Flutter plugin for launching a URL on Android and iOS. Supports
33
web, phone, SMS, and email schemes.
44
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher
5-
version: 5.5.2
5+
version: 5.5.3
66

77
flutter:
88
plugin:

0 commit comments

Comments
 (0)