diff --git a/packages/url_launcher/url_launcher_android/CHANGELOG.md b/packages/url_launcher/url_launcher_android/CHANGELOG.md index 331e7a61c2e..b534ddcb286 100644 --- a/packages/url_launcher/url_launcher_android/CHANGELOG.md +++ b/packages/url_launcher/url_launcher_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.0.38 + +* Updates android implementation to support api 34 broadcast receiver requirements. + ## 6.0.37 * Sets android.defaults.buildfeatures.buildconfig to true for compatibility with AGP 8.0+. diff --git a/packages/url_launcher/url_launcher_android/android/build.gradle b/packages/url_launcher/url_launcher_android/android/build.gradle index cf504cb8afd..2ddd182523f 100644 --- a/packages/url_launcher/url_launcher_android/android/build.gradle +++ b/packages/url_launcher/url_launcher_android/android/build.gradle @@ -62,6 +62,9 @@ android { } dependencies { + + // Java language implementation + implementation "androidx.core:core:1.10.1" implementation 'androidx.annotation:annotation:1.6.0' testImplementation 'junit:junit:4.13.2' testImplementation 'org.mockito:mockito-core:5.1.1' diff --git a/packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java b/packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java index 63b6b71552e..4bfe12986f0 100644 --- a/packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java +++ b/packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java @@ -23,6 +23,7 @@ import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.VisibleForTesting; +import androidx.core.content.ContextCompat; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -143,7 +144,8 @@ public void onCreate(@Nullable Bundle savedInstanceState) { webview.setWebChromeClient(new FlutterWebChromeClient()); // Register receiver that may finish this Activity. - registerReceiver(broadcastReceiver, closeIntentFilter); + ContextCompat.registerReceiver( + this, broadcastReceiver, closeIntentFilter, ContextCompat.RECEIVER_EXPORTED); } @VisibleForTesting diff --git a/packages/url_launcher/url_launcher_android/example/integration_test/url_launcher_test.dart b/packages/url_launcher/url_launcher_android/example/integration_test/url_launcher_test.dart index 28dc79b7af3..7aa221b3e1a 100644 --- a/packages/url_launcher/url_launcher_android/example/integration_test/url_launcher_test.dart +++ b/packages/url_launcher/url_launcher_android/example/integration_test/url_launcher_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:async'; +import 'dart:io'; + import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; @@ -20,4 +23,41 @@ void main() { // sms:, tel:, and mailto: links may not be openable on every device, so // aren't tested here. }); + + testWidgets('launch and close', (WidgetTester _) async { + final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance; + + // Setup fake http server. + final HttpServer server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + unawaited(server.forEach((HttpRequest request) { + if (request.uri.path == '/hello.txt') { + request.response.writeln('Hello, world.'); + } else { + fail('unexpected request: ${request.method} ${request.uri}'); + } + request.response.close(); + })); + // Https to avoid cleartext warning on android. + final String prefixUrl = 'https://${server.address.address}:${server.port}'; + final String primaryUrl = '$prefixUrl/hello.txt'; + + // Launch a url then close. + expect( + await launcher.launch(primaryUrl, + useSafariVC: true, + useWebView: true, + enableJavaScript: false, + enableDomStorage: false, + universalLinksOnly: false, + headers: {}), + true); + await launcher.closeWebView(); + // Delay required to catch android side crashes in onDestroy. + // + // If this test flakes with an android crash during this delay the test + // should be considered failing because this integration test can have a + // false positive pass if the test closes before an onDestroy crash. + // See https://github.com/flutter/flutter/issues/126460 for more info. + await Future.delayed(const Duration(seconds: 5)); + }); } diff --git a/packages/url_launcher/url_launcher_android/pubspec.yaml b/packages/url_launcher/url_launcher_android/pubspec.yaml index 1ef09dbb97f..a80c010cc83 100644 --- a/packages/url_launcher/url_launcher_android/pubspec.yaml +++ b/packages/url_launcher/url_launcher_android/pubspec.yaml @@ -2,8 +2,7 @@ name: url_launcher_android description: Android implementation of the url_launcher plugin. repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22 -version: 6.0.37 - +version: 6.0.38 environment: sdk: ">=2.18.0 <4.0.0" flutter: ">=3.3.0"