diff --git a/android/build.gradle b/android/build.gradle index ee6a0047..3fe16b1c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -29,10 +29,21 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true + consumerProguardFiles 'proguard-rules.pro' } lintOptions { disable 'InvalidPackage' } + buildTypes { + debug { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + release { + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } dependencies { implementation 'androidx.webkit:webkit:1.0.0' implementation 'androidx.browser:browser:1.0.0' diff --git a/android/proguard-rules.pro b/android/proguard-rules.pro new file mode 100644 index 00000000..4930aa46 --- /dev/null +++ b/android/proguard-rules.pro @@ -0,0 +1,17 @@ +# WebView +-keepattributes *JavascriptInterface* +-keepclassmembers class * { + @android.webkit.JavascriptInterface ; +} +-keepclassmembers class * extends android.webkit.WebViewClient { + public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap); + public boolean *(android.webkit.WebView, java.lang.String); + public void *(android.webkit.webView, jav.lang.String); +} +-keepclassmembers class com.pichillilorenzo.flutter_inappbrowser$JavaScriptBridgeInterface { + ; + ; + public *; + private *; +} +-keep class com.pichillilorenzo.flutter_inappbrowser.** { *; } \ No newline at end of file diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java index a4247e05..f1faf117 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java @@ -1,6 +1,8 @@ package com.pichillilorenzo.flutter_inappbrowser; +import android.net.Uri; import android.os.Build; +import android.webkit.ValueCallback; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.PluginRegistry; @@ -15,6 +17,8 @@ public class InAppBrowserFlutterPlugin implements FlutterPlugin { public static InAppBrowser inAppBrowser; public static MyCookieManager myCookieManager; public static CredentialDatabaseHandler credentialDatabaseHandler; + public static ValueCallback uploadMessageArray; + public InAppBrowserFlutterPlugin() {} @@ -61,5 +65,6 @@ public class InAppBrowserFlutterPlugin implements FlutterPlugin { credentialDatabaseHandler.dispose(); credentialDatabaseHandler = null; } + uploadMessageArray = null; } } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewChromeClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewChromeClient.java index 750564e1..d181497c 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewChromeClient.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewChromeClient.java @@ -46,13 +46,11 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR private PluginRegistry.Registrar registrar; private FlutterWebView flutterWebView; private InAppBrowserActivity inAppBrowserActivity; - private ValueCallback mUploadMessageArray; private ValueCallback mUploadMessage; private final static int FILECHOOSER_RESULTCODE = 1; private View mCustomView; private WebChromeClient.CustomViewCallback mCustomViewCallback; - protected FrameLayout mFullscreenContainer; private int mOriginalOrientation; private int mOriginalSystemUiVisibility; @@ -545,10 +543,8 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR } //For Android 5.0+ - public boolean onShowFileChooser( - WebView webView, ValueCallback filePathCallback, - FileChooserParams fileChooserParams) { - mUploadMessageArray = filePathCallback; + public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) { + InAppBrowserFlutterPlugin.uploadMessageArray = filePathCallback; try { Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); @@ -572,9 +568,9 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR @Override public boolean onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == FILECHOOSER_RESULTCODE && (resultCode == RESULT_OK || resultCode == RESULT_CANCELED)) { - mUploadMessageArray.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, data)); + InAppBrowserFlutterPlugin.uploadMessageArray.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, data)); } - return false; + return true; } private MethodChannel getChannel() {