1

I am writing some code for file upload for my mobile app using codename one by passing the URL by set URL("jar:///UploadFile.html") in start() method of codename one. In my Upload File.html while I am trying to upload an image its opening a Dialog Box outside the mobile app,how can I able to open the Dialog Box for suppose gallery and documents inside the codename one app.

Below is my code in codenameone from where I am navigating to the html file

    public void start() {
       if(current != null){
       current.show();
       return;
     }

      Form hi = new Form("");
      final WebBrowser b = new WebBrowser()
      b.setURL("jar:///UploadFile.html");
      b.getUnselectedStyle().setPadding(0, 0, 0, 0);
      b.getUnselectedStyle().setMargin(0, 0, 0, 0);
      BorderLayout blayout = new BorderLayout();
      blayout.setScaleEdges(false);
      hi.setLayout(new BorderLayout());
      hi.addComponent(BorderLayout.CENTER, b);
      hi.show();
    }

Please find Below html code

 <pre>
 input type="file" multiple accept="image/*"
</pre>

Please find the below screen shot for file upload

  [1]: https://i.stack.imgur.com/FMzcr.png

What am I missing?

Thank you.

Prabhat Sinha
  • 1,500
  • 20
  • 32
A Baruah
  • 141
  • 5

1 Answers1

0

There is no portable way to handle file choosers in the browser in Android. It's just inherently broken.

A workaround for the upload use case is to use Codename One which provides a MultipartRequest class that allows you to upload a file easily in a way that's compatible to the browser. There is also a new file chooser cn1lib you might be able to leverage in the extensions.

Community
  • 1
  • 1
Shai Almog
  • 51,749
  • 5
  • 35
  • 65