1. Hot New Devices! HTC One M9 | Samsung Galaxy S6 | LG G4

File Upload Button does nto work in a Webview


  1. Foxcitiesjd

    Foxcitiesjd New Member

    I need to be able to open a file upload menu from AndroidAddMember.aspx page in a web view. I found this fix but I dont think im implementing it correctly.

    m0s' programming adventure: File upload in through WebView on Android

    The file upload button works fine in a browser on phone and pc but once in a web view the button does not work.
    I embed the page with the button in my first case statement below.
    Do i need to set the web view differently in that case statement to get the code above it to work? I wrapped the new code in these brackets //+++++++++++++++++++++

    Any help would be great. Thanks
    //+++++++++++ New Code to fix the button issue+++++++++++++++
    WebView wv;
    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;

    }
    }


    public void onCreate1(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    wv = new WebView(this);
    wv.setWebViewClient(new WebViewClient());
    wv.setWebChromeClient(new 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/*");
    MyGreatActivity.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);

    }
    });

    setContentView(wv);
    }

    //++++++++++++++ End of new code to fix the button issue +++++++++++++++++++++
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.register:
    mWebView2 = (WebView) findViewById(R.id.webview);
    mWebView2.getSettings().setJavaScriptEnabled(true);
    mWebView2.loadUrl("http://www.Mysite.com/AndroidAddMember.aspx");
    mWebView2.setWebViewClient(new HelloWebViewClient());
    return true;
    case R.id.ratewomen:
    mWebView3 = (WebView) findViewById(R.id.webview);
    mWebView3.getSettings().setJavaScriptEnabled(true);
    mWebView3.loadUrl("http://mysite.com/gadgets.aspx");
    mWebView3.setWebViewClient(new HelloWebViewClient());
    return true;
    case R.id.ratemen:
    mWebView4 = (WebView) findViewById(R.id.webview);
    mWebView4.getSettings().setJavaScriptEnabled(true);
    mWebView4.loadUrl("http://mysite.com/gadgetsmall.aspx");
    mWebView4.setWebViewClient(new HelloWebViewClient());
    return true;
    default:
    return super.onOptionsItemSelected(item);
    }
    }

    Advertisement

Share This Page