From 4b2490157134fbd493039693063eea84c88c2a8c Mon Sep 17 00:00:00 2001 From: Michael Rittmeister Date: Sat, 26 Sep 2020 11:35:06 +0200 Subject: [PATCH 1/5] Add support for Android 11 - Reflect package visibility settings in documentation - Upgrade android projects (lib & example) - Cleanup ChromeSafariBrowserManager.java - Upgrade Android dependencies --- README.md | 2 ++ android/build.gradle | 2 +- android/src/main/AndroidManifest.xml | 7 ++++++ .../ChromeSafariBrowserManager.java | 22 +++++++++---------- example/android/app/build.gradle | 6 ++--- example/android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 4 ++-- lib/src/chrome_safari_browser.dart | 2 ++ 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d398a02e0..d82c572f2 100755 --- a/README.md +++ b/README.md @@ -75,6 +75,8 @@ or **Android API 19+** if you enable the `useHybridComposition` Android-specific - Check the official [Network security configuration - "Opt out of cleartext traffic"](https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted) section. - Also, check this StackOverflow issue answer: [Cleartext HTTP traffic not permitted](https://stackoverflow.com/a/50834600/4637638). +If you want to use the `ChromeSafariBrowser` on Android 11+ you need to specify your app querying for `android.support.customtabs.action.CustomTabsService` in your `AndroidManifest.xml` you can read more about it here: https://developers.google.com/web/android/custom-tabs/best-practices#applications_targeting_android_11_api_level_30_or_above + ### IMPORTANT Note for iOS If you are starting a new fresh app, you need to create the Flutter App with `flutter create --androidx -i swift` diff --git a/android/build.gradle b/android/build.gradle index e01ae94fd..43194fe30 100755 --- a/android/build.gradle +++ b/android/build.gradle @@ -48,6 +48,6 @@ android { implementation 'androidx.webkit:webkit:1.3.0' implementation 'androidx.browser:browser:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0-rc02' - implementation 'com.squareup.okhttp3:mockwebserver:3.11.0' + implementation 'com.squareup.okhttp3:mockwebserver:3.14.7' } } diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index a7309e1ef..9aaca72f0 100755 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -9,4 +9,11 @@ android:name="io.flutter.embedded_views_preview" android:value="true" /> + + + + + + \ No newline at end of file diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ChromeSafariBrowserManager.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ChromeSafariBrowserManager.java index 4f50a8040..5691c63f5 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ChromeSafariBrowserManager.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ChromeSafariBrowserManager.java @@ -33,19 +33,19 @@ public ChromeSafariBrowserManager(BinaryMessenger messenger) { @Override public void onMethodCall(final MethodCall call, final MethodChannel.Result result) { final Activity activity = Shared.activity; - final String uuid = (String) call.argument("uuid"); + final String uuid = call.argument("uuid"); switch (call.method) { case "open": { - String url = (String) call.argument("url"); - HashMap options = (HashMap) call.argument("options"); - List> menuItemList = (List>) call.argument("menuItemList"); - String uuidFallback = (String) call.argument("uuidFallback"); - Map headersFallback = (Map) call.argument("headersFallback"); - HashMap optionsFallback = (HashMap) call.argument("optionsFallback"); - HashMap contextMenuFallback = (HashMap) call.argument("contextMenuFallback"); - Integer windowIdFallback = (Integer) call.argument("windowIdFallback"); + String url = call.argument("url"); + HashMap options = call.argument("options"); + List> menuItemList = call.argument("menuItemList"); + String uuidFallback = call.argument("uuidFallback"); + Map headersFallback = call.argument("headersFallback"); + HashMap optionsFallback = call.argument("optionsFallback"); + HashMap contextMenuFallback = call.argument("contextMenuFallback"); + Integer windowIdFallback = call.argument("windowIdFallback"); open(activity, uuid, url, options, menuItemList, uuidFallback, headersFallback, optionsFallback, contextMenuFallback, windowIdFallback, result); } break; @@ -71,7 +71,7 @@ public void open(Activity activity, String uuid, String url, HashMap Date: Fri, 29 Jan 2021 01:11:04 +0100 Subject: [PATCH 2/5] Update ChromeSafariBrowserManager.java --- .../ChromeSafariBrowserManager.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ChromeSafariBrowserManager.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ChromeSafariBrowserManager.java index 5691c63f5..3526913c8 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ChromeSafariBrowserManager.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/ChromeSafariBrowserManager.java @@ -33,19 +33,19 @@ public ChromeSafariBrowserManager(BinaryMessenger messenger) { @Override public void onMethodCall(final MethodCall call, final MethodChannel.Result result) { final Activity activity = Shared.activity; - final String uuid = call.argument("uuid"); + final String uuid = (String) call.argument("uuid"); switch (call.method) { case "open": { - String url = call.argument("url"); - HashMap options = call.argument("options"); - List> menuItemList = call.argument("menuItemList"); - String uuidFallback = call.argument("uuidFallback"); - Map headersFallback = call.argument("headersFallback"); - HashMap optionsFallback = call.argument("optionsFallback"); - HashMap contextMenuFallback = call.argument("contextMenuFallback"); - Integer windowIdFallback = call.argument("windowIdFallback"); + String url = (String) call.argument("url"); + HashMap options = (HashMap) call.argument("options"); + List> menuItemList = (List>) call.argument("menuItemList"); + String uuidFallback = (String) call.argument("uuidFallback"); + Map headersFallback = (Map) call.argument("headersFallback"); + HashMap optionsFallback = (HashMap) call.argument("optionsFallback"); + HashMap contextMenuFallback = (HashMap) call.argument("contextMenuFallback"); + Integer windowIdFallback = (Integer) call.argument("windowIdFallback"); open(activity, uuid, url, options, menuItemList, uuidFallback, headersFallback, optionsFallback, contextMenuFallback, windowIdFallback, result); } break; @@ -71,7 +71,7 @@ public void open(Activity activity, String uuid, String url, HashMap Date: Fri, 29 Jan 2021 01:17:50 +0100 Subject: [PATCH 3/5] Update chrome_safari_browser.dart --- lib/src/chrome_safari_browser.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/chrome_safari_browser.dart b/lib/src/chrome_safari_browser.dart index 2f6eb626b..fbbca4744 100755 --- a/lib/src/chrome_safari_browser.dart +++ b/lib/src/chrome_safari_browser.dart @@ -11,7 +11,7 @@ import 'in_app_browser.dart'; /// ///[browserFallback] represents the [InAppBrowser] instance fallback in case `Chrome Custom Tabs`/`SFSafariViewController` is not available. /// -///Note: Requires modification of Android 11+: https://developers.google.com/web/android/custom-tabs/best-practices#applications_targeting_android_11_api_level_30_or_above +///**NOTE**: If you want to use the `ChromeSafariBrowser` class on Android 11+ you need to specify your app querying for `android.support.customtabs.action.CustomTabsService` in your `AndroidManifest.xml` (you can read more about it here: https://developers.google.com/web/android/custom-tabs/best-practices#applications_targeting_android_11_api_level_30_or_above). class ChromeSafariBrowser { late String uuid; InAppBrowser? browserFallback; From abf0c64d9de2e4357e8db1d781194e698a66de25 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Fri, 29 Jan 2021 01:19:20 +0100 Subject: [PATCH 4/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7d7cfe02..115f737ae 100755 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ Classes: - [ContextMenu](#contextmenu-class): This class represents the WebView context menu. - [HeadlessInAppWebView](#headlessinappwebview-class): Class that represents a WebView in headless mode. It can be used to run a WebView in background without attaching an `InAppWebView` to the widget tree. - [InAppBrowser](#inappbrowser-class): In-App Browser using native WebView. -- [ChromeSafariBrowser](#chromesafaribrowser-class): In-App Browser using [Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android / [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS. If you want to use the `ChromeSafariBrowser` on Android 11+ you need to specify your app querying for `android.support.customtabs.action.CustomTabsService` in your `AndroidManifest.xml` (you can read more about it here: https://developers.google.com/web/android/custom-tabs/best-practices#applications_targeting_android_11_api_level_30_or_above). +- [ChromeSafariBrowser](#chromesafaribrowser-class): In-App Browser using [Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android / [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS. If you want to use the `ChromeSafariBrowser` class on Android 11+ you need to specify your app querying for `android.support.customtabs.action.CustomTabsService` in your `AndroidManifest.xml` (you can read more about it here: https://developers.google.com/web/android/custom-tabs/best-practices#applications_targeting_android_11_api_level_30_or_above). - [InAppLocalhostServer](#inapplocalhostserver-class): This class allows you to create a simple server on `http://localhost:[port]/`. The default `port` value is `8080`. - [CookieManager](#cookiemanager-class): This class implements a singleton object (shared instance) which manages the cookies used by WebView instances. **NOTE for iOS**: available from iOS 11.0+. - [HttpAuthCredentialDatabase](#httpauthcredentialdatabase-class): This class implements a singleton object (shared instance) which manages the shared HTTP auth credentials cache. @@ -1164,7 +1164,7 @@ Specific events of the `InAppBrowser` class are: [Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android / [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS. -If you want to use the `ChromeSafariBrowser` on Android 11+ you need to specify your app querying for `android.support.customtabs.action.CustomTabsService` in your `AndroidManifest.xml` (you can read more about it here: https://developers.google.com/web/android/custom-tabs/best-practices#applications_targeting_android_11_api_level_30_or_above). +If you want to use the `ChromeSafariBrowser` class on Android 11+ you need to specify your app querying for `android.support.customtabs.action.CustomTabsService` in your `AndroidManifest.xml` (you can read more about it here: https://developers.google.com/web/android/custom-tabs/best-practices#applications_targeting_android_11_api_level_30_or_above). You can initialize the `ChromeSafariBrowser` instance with an `InAppBrowser` fallback instance. From cb474e5537f54e039aee84adb8c10fc7a3836fbe Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Fri, 29 Jan 2021 01:20:17 +0100 Subject: [PATCH 5/5] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 115f737ae..0b698da25 100755 --- a/README.md +++ b/README.md @@ -75,6 +75,8 @@ or **Android API 19+** if you enable the `useHybridComposition` Android-specific - Check the official [Network security configuration - "Opt out of cleartext traffic"](https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted) section. - Also, check this StackOverflow issue answer: [Cleartext HTTP traffic not permitted](https://stackoverflow.com/a/50834600/4637638). +If you want to use the `ChromeSafariBrowser` class on Android 11+ you need to specify your app querying for `android.support.customtabs.action.CustomTabsService` in your `AndroidManifest.xml` (you can read more about it here: https://developers.google.com/web/android/custom-tabs/best-practices#applications_targeting_android_11_api_level_30_or_above). + #### Debugging Android WebViews On Android, in order to enable/disable debugging WebViews using `chrome://inspect` on Chrome, you should use the `AndroidInAppWebViewController.setWebContentsDebuggingEnabled(bool debuggingEnabled)` static method. @@ -205,7 +207,7 @@ Classes: - [ContextMenu](#contextmenu-class): This class represents the WebView context menu. - [HeadlessInAppWebView](#headlessinappwebview-class): Class that represents a WebView in headless mode. It can be used to run a WebView in background without attaching an `InAppWebView` to the widget tree. - [InAppBrowser](#inappbrowser-class): In-App Browser using native WebView. -- [ChromeSafariBrowser](#chromesafaribrowser-class): In-App Browser using [Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android / [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS. If you want to use the `ChromeSafariBrowser` class on Android 11+ you need to specify your app querying for `android.support.customtabs.action.CustomTabsService` in your `AndroidManifest.xml` (you can read more about it here: https://developers.google.com/web/android/custom-tabs/best-practices#applications_targeting_android_11_api_level_30_or_above). +- [ChromeSafariBrowser](#chromesafaribrowser-class): In-App Browser using [Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android / [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS. - [InAppLocalhostServer](#inapplocalhostserver-class): This class allows you to create a simple server on `http://localhost:[port]/`. The default `port` value is `8080`. - [CookieManager](#cookiemanager-class): This class implements a singleton object (shared instance) which manages the cookies used by WebView instances. **NOTE for iOS**: available from iOS 11.0+. - [HttpAuthCredentialDatabase](#httpauthcredentialdatabase-class): This class implements a singleton object (shared instance) which manages the shared HTTP auth credentials cache.