0

Why not working choose file option in webview?I have a wordpress website ,i used contactform7 plugin for upload-file option.but when , click on choose-file button in webview , this is not working.

MainActivity.java

import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
import android.webkit.ValueCallback;
import android.content.Intent;

public class MainActivity extends AppCompatActivity {
    private WebView myWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myWebView = (WebView)findViewById(R.id.webView);
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        myWebView.loadUrl("http://grocerydoorstep.com");
        myWebView.setWebViewClient(new CustomWebViewClient());
    }

    public class CustomWebViewClient extends WebViewClient {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            findViewById(R.id.progressBar1).setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            findViewById(R.id.progressBar1).setVisibility(View.GONE);
        }

    }
    public void onBackPressed() {
        if (myWebView.canGoBack()) {
            myWebView.goBack();
        } else {
            super.onBackPressed();
        }
    }
}
ArK
  • 19,864
  • 65
  • 105
  • 136

2 Answers2

0

this is the only solution that i found that works!

WebView webview;

private ValueCallback<Uri> mUploadMessage;
private final static int FILECHOOSER_RESULTCODE = 1;

@Override
protected void onActivityResult(int requestCode, int resultCode,
    Intent intent) {
if (requestCode == FILECHOOSER_RESULTCODE) {
    if (null == mUploadMessage)
        return;
    Uri result = intent == null || resultCode != RESULT_OK ? null
            : intent.getData();
    mUploadMessage.onReceiveValue(result);
    mUploadMessage = null;

   }
}

// Next part

class MyWebChromeClient extends WebChromeClient {
// The undocumented magic method override
// Eclipse will swear at you if you try to put @Override here
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);
   }
 }
Atman Bhatt
  • 1,245
  • 8
  • 14
0

Hi,maybe this link will be useful to you. Kindly check it out file chooser inside Webview In the above link they explained about how to pick a file and how to capture a file using camera and get its path from Webview .

Senthilvel S
  • 311
  • 1
  • 7
  • 21