[ 
https://issues.apache.org/jira/browse/CB-9148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15669717#comment-15669717
 ] 

Darron Park edited comment on CB-9148 at 11/16/16 8:12 AM:
-----------------------------------------------------------

The Code below fixed this problem for me.
Maybe someone who can contribute this code to inappbrowser source.

> Source: InAppBrowser.java

> First, I imported some Classes
----------------------------------------------------
import android.util.Log;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
----------------------------------------------------
> Second, I added some variables in InAppBrowser class.
----------------------------------------------------
        private ValueCallback<Uri> mUploadMessage;
        private ValueCallback<Uri[]> mUploadMessageLollipop;
        private final static int FILECHOOSER_RESULTCODE = 1;
        private final static int FILECHOOSER_LOLLIPOP_RESULTCODE = 2;
----------------------------------------------------

> Then, I changed the code from...
----------------------------------------------------
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
----------------------------------------------------
> to...
----------------------------------------------------
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView) {

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String 
acceptType, String capture) {
                mUploadMessage = uploadMsg;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");
                Log.i("mytag", "openFileChooser Executed");
                cordova.getActivity().startActivityForResult(
                                Intent.createChooser(i, "File Chooser"),
                                FILECHOOSER_RESULTCODE);
        }

        public void showFileChooser(ValueCallback<String[]> filePathCallback, 
String acceptType, boolean paramBoolean) {
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");
                Log.i("mytag", "showFileChooser Executed");
                cordova.getActivity().startActivityForResult(
                                Intent.createChooser(i, "File Chooser"),
                                FILECHOOSER_RESULTCODE);
        }

        // For Android 5.0+
        public boolean onShowFileChooser(
                        WebView webView, ValueCallback<Uri[]> filePathCallback,
                        WebChromeClient.FileChooserParams fileChooserParams) {
                mUploadMessageLollipop = filePathCallback;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");
                Log.d("MainActivity", "5.0+");
                
cordova.getActivity().startActivityForResult(Intent.createChooser(i, "File 
Chooser"), FILECHOOSER_LOLLIPOP_RESULTCODE);

                return true;
        }

});
----------------------------------------------------

> Also added method below to InAppBrowser class
----------------------------------------------------
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        Log.i("mytag", "onActivityResult");
        if (requestCode == FILECHOOSER_RESULTCODE) {
                Log.i("mytag", "onActivityResult (File Chooser)");
                if (null == mUploadMessage)
                        return;
                Uri result = intent == null || resultCode != 
cordova.getActivity().RESULT_OK ? null
                                : intent.getData();
                mUploadMessage.onReceiveValue(result);
                mUploadMessage = null;
        }
        else if(requestCode == FILECHOOSER_LOLLIPOP_RESULTCODE) {
                Log.i("mytag", "onActivityResult (File Chooser Lollipop)");
                if (mUploadMessageLollipop == null) return ;
                            if (Build.VERSION.SDK_INT >= 
Build.VERSION_CODES.LOLLIPOP) {
                
mUploadMessageLollipop.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode,
 intent));
            }
                mUploadMessageLollipop = null;
        }
}
----------------------------------------------------

I can't understand why this basic function is not yet implemented to 
InAppBrowser :(


was (Author: jay8585):
The Code below fixed this problem for me.
Maybe someone who can contribute this code to inappbrowser source.

> Source: InAppBrowser.java

> First, I added some variables in InAppBrowser class.
----------------------------------------------------
        private ValueCallback<Uri> mUploadMessage;
        private ValueCallback<Uri[]> mUploadMessageLollipop;
        private final static int FILECHOOSER_RESULTCODE = 1;
        private final static int FILECHOOSER_LOLLIPOP_RESULTCODE = 2;
----------------------------------------------------

> Then, I changed the code from...
----------------------------------------------------
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
----------------------------------------------------
> to...
----------------------------------------------------
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView) {

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String 
acceptType, String capture) {
                mUploadMessage = uploadMsg;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");
                Log.i("mytag", "openFileChooser Executed");
                cordova.getActivity().startActivityForResult(
                                Intent.createChooser(i, "File Chooser"),
                                FILECHOOSER_RESULTCODE);
        }

        public void showFileChooser(ValueCallback<String[]> filePathCallback, 
String acceptType, boolean paramBoolean) {
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");
                Log.i("mytag", "showFileChooser Executed");
                cordova.getActivity().startActivityForResult(
                                Intent.createChooser(i, "File Chooser"),
                                FILECHOOSER_RESULTCODE);
        }

        // For Android 5.0+
        public boolean onShowFileChooser(
                        WebView webView, ValueCallback<Uri[]> filePathCallback,
                        WebChromeClient.FileChooserParams fileChooserParams) {
                mUploadMessageLollipop = filePathCallback;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");
                Log.d("MainActivity", "5.0+");
                
cordova.getActivity().startActivityForResult(Intent.createChooser(i, "File 
Chooser"), FILECHOOSER_LOLLIPOP_RESULTCODE);

                return true;
        }

});
----------------------------------------------------

> Also added method below to InAppBrowser class
----------------------------------------------------
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        Log.i("mytag", "onActivityResult");
        if (requestCode == FILECHOOSER_RESULTCODE) {
                Log.i("mytag", "onActivityResult (File Chooser)");
                if (null == mUploadMessage)
                        return;
                Uri result = intent == null || resultCode != 
cordova.getActivity().RESULT_OK ? null
                                : intent.getData();
                mUploadMessage.onReceiveValue(result);
                mUploadMessage = null;
        }
        else if(requestCode == FILECHOOSER_LOLLIPOP_RESULTCODE) {
                Log.i("mytag", "onActivityResult (File Chooser Lollipop)");
                if (mUploadMessageLollipop == null) return ;
                
mUploadMessageLollipop.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode,
 intent));
                mUploadMessageLollipop = null;
        }
}
----------------------------------------------------

I can't understand why this basic function is not yet implemented to 
InAppBrowser :(

> Add support for file picker in InAppBrowser
> -------------------------------------------
>
>                 Key: CB-9148
>                 URL: https://issues.apache.org/jira/browse/CB-9148
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: Plugin InAppBrowser
>    Affects Versions: 3.5.0, 3.6.0
>         Environment: problem in Android, the camera roll never opens  (iOS 
> working OK)
>            Reporter: Tomas Rawski
>              Labels: Android, camera, file, input, roll, triaged
>
> reproduce : 
> open the inAppBrowser: http://www.plupload.com/examples
> click in Add files.
> This works ok when I call it from the _system or _self. But not for _blank.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to