How do I upload multiple images in my WebView?

CodeReaper

How can I make the file upload in my app's WebView behave like in the browser app?

I am trying to make a WebView in my Android application allow uploading multiple images taken with the camera.

When I have the HTML code below open in the browser app, I can attach multiple pictures. When I have the same code in my WebView in my app, the button won't even open a dialog.

<form method="post" action="/save/images" name="send" id="send" enctype="multipart/form-data">
   <input type="file" name="data[]" id="camera" multiple="">
   <input type="submit" name="send">
</form>

Here's a link to the above HTML if you want to try it out: http://codereaper.com/bugspray/so/25251993/html-sendimages/

The point here is the Android application itself have nothing to do with this, the loaded URL contain a webpage made to function in Android's browser application where you can use the camera to upload a bunch of images.

The current state of my attempts consists of giving permissions to the app:

<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>

Allowing JavaScript and FileAcess when creating the WebView:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_report);

    WebView webView = (WebView) findViewById(R.id.report_webview);

    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    webView.setWebChromeClient(new WebChromeClient());
    webView.getSettings().setAllowFileAccess(true);

    showProgressDialog(R.string.please_wait_title, R.string.please_wait_description);

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            closeProgressDialog();
        }
    }
    );

    webView.loadUrl("http://codereaper.com/bugspray/so/25251993/html-sendimages/");
}

In my searches I have found a lot of references to use an undocumented feature 'openFileChooser':

   new WebChromeClient() {
        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            mUploadMessage = uploadMsg;
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.addCategory(Intent.CATEGORY_OPENABLE);
            i.setType("image/*");
            Cv5appActivity.this.startActivityForResult(
                    Intent.createChooser(i, "Image Browser"),
                    FILECHOOSER_RESULTCODE);
        }
    }

I am supporting only newer Android versions (4.3 and above) and would like to do this in supported and documented way, but will use this method if no other method exist. However I do not see how the 'openFileChooser' method will:

  • allow multiple images to taken/uploaded
  • hand the images captured back to the form/ajax/html on the webpage

Any advice would be appreciated in order to make the WebView act like the browser app on Android or making WebChromeClient able to handle multiple images and "hand them back to the WebView".

Cheers

CodeReaper

I did solve all my problems a while back using the other answers on SO that involves the 'openFileChooser' methods. The key piece of information I needed to discover/understand was the ValueCallback<Uri> which is both the way of handing the selected images back, but also puts the responsibility of handling multiple images to the WebView.

You are handed a ValueCallback<Uri> while implementing the 'openFileChooser' methods and you are then responsible for calling its callback to hand back with the selected image or null, like:

mUploadMessage.onReceiveValue(null);

Also note that if you do not call the callback, your WebView will stop working right.

UPDATE:

Recently the issue reappeared so now I am using a fork of https://github.com/delight-im/Android-AdvancedWebView - so far it is working beautifully and I didn't have to code it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I upload multiple images in my WebView?

From Dev

how do i upload multiple images using Multiparty Entity in Android

From Dev

How do I upload multiple images using multer in node js?

From Dev

How do I to show images before upload?

From Dev

How do I get iPads to upload images?

From Dev

How do I upload multiple images and text file in a single form with the different button in Codeigniter?

From Dev

How do I build in images to my app

From Dev

How do I upload multiple files with Protractor?

From Dev

How do I scale multiple images in javascript?

From Dev

How do I delete multiple images in docker?

From Dev

How do I delete multiple images in docker?

From Dev

How do I set the license for images on my site in Google Images?

From Dev

How do I set the license for images on my site in Google Images?

From Dev

How do I make sure my webview can scale with devices?

From Dev

My webview video is continously loading, how do I get it to play?

From Dev

how enable multiple file upload in webview

From Dev

How can i add multiple images to my scrollView in ios

From Dev

How do I saturate my upload and download available bandwidth?

From Dev

How do I upload a hashed password to my database?

From Dev

How do i upload a file to my ftp at weebly.com?

From Dev

How do i upload text file to my ftp every minute?

From Dev

How do i upload my LibGDX game online ?

From Dev

How do I symlink my product images in production on a Capistrano deploy?

From Dev

How do I configure my grails app to skip preprocessing images?

From Dev

How do I load a batch of images to be processed by my tfjs model

From Dev

How do I get different background images on my dual monitors?

From Dev

How do I copy a folder full of images to my github repo?

From Dev

How do I add images to my PHP blog?

From Dev

How do i add attributes to my images with javascript?

Related Related

  1. 1

    How do I upload multiple images in my WebView?

  2. 2

    how do i upload multiple images using Multiparty Entity in Android

  3. 3

    How do I upload multiple images using multer in node js?

  4. 4

    How do I to show images before upload?

  5. 5

    How do I get iPads to upload images?

  6. 6

    How do I upload multiple images and text file in a single form with the different button in Codeigniter?

  7. 7

    How do I build in images to my app

  8. 8

    How do I upload multiple files with Protractor?

  9. 9

    How do I scale multiple images in javascript?

  10. 10

    How do I delete multiple images in docker?

  11. 11

    How do I delete multiple images in docker?

  12. 12

    How do I set the license for images on my site in Google Images?

  13. 13

    How do I set the license for images on my site in Google Images?

  14. 14

    How do I make sure my webview can scale with devices?

  15. 15

    My webview video is continously loading, how do I get it to play?

  16. 16

    how enable multiple file upload in webview

  17. 17

    How can i add multiple images to my scrollView in ios

  18. 18

    How do I saturate my upload and download available bandwidth?

  19. 19

    How do I upload a hashed password to my database?

  20. 20

    How do i upload a file to my ftp at weebly.com?

  21. 21

    How do i upload text file to my ftp every minute?

  22. 22

    How do i upload my LibGDX game online ?

  23. 23

    How do I symlink my product images in production on a Capistrano deploy?

  24. 24

    How do I configure my grails app to skip preprocessing images?

  25. 25

    How do I load a batch of images to be processed by my tfjs model

  26. 26

    How do I get different background images on my dual monitors?

  27. 27

    How do I copy a folder full of images to my github repo?

  28. 28

    How do I add images to my PHP blog?

  29. 29

    How do i add attributes to my images with javascript?

HotTag

Archive