Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML input type 'file' is not working on webview in android. Is there any way to upload file using webview android?

Tags:

html

android

this is my browsing code of html.

This is my android code which load html file for browse file and upload on server.

        runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            System.out.println(AndroidConstants.MAIN_URL());
            toast(AndroidConstants.MAIN_URL());
            webView.loadUrl(AndroidConstants.MAIN_URL());
            webView.setDownloadListener(new DownloadListener() {
                @Override
                public void onDownloadStart(String url, String userAgent,
                        String contentDisposition, String mimetype,
                        long contentLength) {
                    // TODO Auto-generated method stub

                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(url));
                    startActivity(i);

                }

                  public void openFileChooser(ValueCallback<Uri> uploadMsg) {  
                      Intent i = new Intent(Intent.ACTION_GET_CONTENT);  
                      i.addCategory(Intent.CATEGORY_OPENABLE);  
                      i.setType("image/*");  
                        WebViewActivity.this.startActivityForResult(Intent.createChooser(i,"Image Chooser"), 2533);  
                     }

                     public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
                         openFileChooser(uploadMsg);
                     }                   

                     public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
                         openFileChooser(uploadMsg);
                     }   
            });


        }
    });

    JavaScriptInterface jsInterface = new JavaScriptInterface(this);
    webView.getSettings().setJavaScriptEnabled(true);

i want upload video file using html5 on android application.

like image 934
Shahadeo Avatar asked Mar 14 '15 04:03

Shahadeo


People also ask

How do I open an HTML file in WebView?

The WebView method to load our file takes a URI , so we need to access the HTML file using that URI . Since we stored it in the assets folder, we can access it using file:///android_asset/{file_name} .

Is it possible to get data from HTML forms into Android while WebView?

Yes you can, you can use javascript to get webpage content. Then use the webview jsInterface to return the content to you java code.

Which method is used to load HTML content in WebView?

The loadUrl() and loadData() methods of Android WebView class are used to load and display web page.

How do I enable JavaScript on Android WebView?

JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView . You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.


1 Answers

This issue has already been asked and answered here: File Upload in WebView

Also check this: https://code.google.com/p/android/issues/detail?id=62220

You can use this class: https://github.com/delight-im/Android-AdvancedWebView

like image 182
javaEntu Avatar answered Sep 29 '22 08:09

javaEntu