fix choose file callback in android
This commit is contained in:
parent
2811fce463
commit
17c005561b
|
@ -1,5 +1,6 @@
|
||||||
package com.pichillilorenzo.flutter_inappbrowser.InAppWebView;
|
package com.pichillilorenzo.flutter_inappbrowser.InAppWebView;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
@ -33,7 +34,10 @@ import java.util.Map;
|
||||||
import io.flutter.plugin.common.MethodChannel;
|
import io.flutter.plugin.common.MethodChannel;
|
||||||
import io.flutter.plugin.common.PluginRegistry;
|
import io.flutter.plugin.common.PluginRegistry;
|
||||||
|
|
||||||
public class InAppWebChromeClient extends WebChromeClient {
|
import static android.app.Activity.RESULT_CANCELED;
|
||||||
|
import static android.app.Activity.RESULT_OK;
|
||||||
|
|
||||||
|
public class InAppWebChromeClient extends WebChromeClient implements PluginRegistry.ActivityResultListener {
|
||||||
|
|
||||||
protected static final String LOG_TAG = "IABWebChromeClient";
|
protected static final String LOG_TAG = "IABWebChromeClient";
|
||||||
private PluginRegistry.Registrar registrar;
|
private PluginRegistry.Registrar registrar;
|
||||||
|
@ -56,18 +60,18 @@ public class InAppWebChromeClient extends WebChromeClient {
|
||||||
this.inAppBrowserActivity = (InAppBrowserActivity) obj;
|
this.inAppBrowserActivity = (InAppBrowserActivity) obj;
|
||||||
else if (obj instanceof FlutterWebView)
|
else if (obj instanceof FlutterWebView)
|
||||||
this.flutterWebView = (FlutterWebView) obj;
|
this.flutterWebView = (FlutterWebView) obj;
|
||||||
|
|
||||||
|
registrar.addActivityResultListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getDefaultVideoPoster()
|
public Bitmap getDefaultVideoPoster() {
|
||||||
{
|
|
||||||
if (mCustomView == null) {
|
if (mCustomView == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return BitmapFactory.decodeResource(this.registrar.activeContext().getResources(), 2130837573);
|
return BitmapFactory.decodeResource(this.registrar.activeContext().getResources(), 2130837573);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onHideCustomView()
|
public void onHideCustomView() {
|
||||||
{
|
|
||||||
View decorView = this.registrar.activity().getWindow().getDecorView();
|
View decorView = this.registrar.activity().getWindow().getDecorView();
|
||||||
((FrameLayout) decorView).removeView(this.mCustomView);
|
((FrameLayout) decorView).removeView(this.mCustomView);
|
||||||
this.mCustomView = null;
|
this.mCustomView = null;
|
||||||
|
@ -77,10 +81,8 @@ public class InAppWebChromeClient extends WebChromeClient {
|
||||||
this.mCustomViewCallback = null;
|
this.mCustomViewCallback = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
|
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback) {
|
||||||
{
|
if (this.mCustomView != null) {
|
||||||
if (this.mCustomView != null)
|
|
||||||
{
|
|
||||||
onHideCustomView();
|
onHideCustomView();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -392,8 +394,7 @@ public class InAppWebChromeClient extends WebChromeClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, android.os.Message resultMsg)
|
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, android.os.Message resultMsg) {
|
||||||
{
|
|
||||||
WebView.HitTestResult result = view.getHitTestResult();
|
WebView.HitTestResult result = view.getHitTestResult();
|
||||||
String data = result.getExtra();
|
String data = result.getExtra();
|
||||||
Map<String, Object> obj = new HashMap<>();
|
Map<String, Object> obj = new HashMap<>();
|
||||||
|
@ -518,10 +519,9 @@ public class InAppWebChromeClient extends WebChromeClient {
|
||||||
public boolean onShowFileChooser(
|
public boolean onShowFileChooser(
|
||||||
WebView webView, ValueCallback<Uri[]> filePathCallback,
|
WebView webView, ValueCallback<Uri[]> filePathCallback,
|
||||||
FileChooserParams fileChooserParams) {
|
FileChooserParams fileChooserParams) {
|
||||||
if (mUploadMessageArray != null) {
|
if (mUploadMessageArray == null) {
|
||||||
mUploadMessageArray.onReceiveValue(null);
|
|
||||||
}
|
|
||||||
mUploadMessageArray = filePathCallback;
|
mUploadMessageArray = filePathCallback;
|
||||||
|
}
|
||||||
|
|
||||||
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
|
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
|
@ -540,4 +540,13 @@ public class InAppWebChromeClient extends WebChromeClient {
|
||||||
private MethodChannel getChannel() {
|
private MethodChannel getChannel() {
|
||||||
return (inAppBrowserActivity != null) ? InAppBrowserFlutterPlugin.inAppBrowser.channel : flutterWebView.channel;
|
return (inAppBrowserActivity != null) ? InAppBrowserFlutterPlugin.inAppBrowser.channel : flutterWebView.channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
@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));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue