-1

I have a register page that has a file upload button on it. This is a aspx page in C#.

When i run it in a browser it works fine. When i run it in a web view in an android app it does not launch the file menu in you android phone. When i run the page in a browser on my android phone it lanuches the file menu on my phone just fine.

How do i get it to work in a web view.

My asp tag.

<asp:FileUpload ID="FileUpload1" runat="server" Height="30px" Width="217px" />

my android web view

case R.id.register:            
mWebView2 = (WebView) findViewById(R.id.webview);    
mWebView2.getSettings().setJavaScriptEnabled(true);    
mWebView2.loadUrl("www.mysite.com/AndroidAddMember.aspx");
mWebView2.setWebViewClient(new HelloWebViewClient());           
return true;  

I tried to implement your code that you suplied. Im getting an error on FILECHOOSER_RESULTCODE now. The error is FILECHOOSER_RESULTCODE cannot be resolved to a variable.

case R.id.register:            
        //mWebView2 = (WebView) findViewById(R.id.webview);    
        //mWebView2.getSettings().setJavaScriptEnabled(true);    
        //mWebView2.loadUrl("http://www.bangmeornot.com/AndroidAddMember.aspx");
        //mWebView2.setWebViewClient(new HelloWebViewClient());   
        mWebView2.setWebChromeClient(new WebChromeClient()   
        {   
            //The undocumented magic method override   
            //Eclipse will swear at you if you try to put @Override here   
            public void openFileChooser(ValueCallback<URL> uploadMsg) {   

            ValueCallback<URL> mUploadMessage = uploadMsg;   
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);   
            i.addCategory(Intent.CATEGORY_OPENABLE);   
            i.setType("image/*");   
            BangMeorNot.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);        
            }   
        });   

        return true;    
CsharpBeginner
  • 1,753
  • 8
  • 38
  • 68

1 Answers1

1

Apparently the stock browser uses an undocumented method to accomplish file uploads. Here's what you have to do to enable this functionality in your app:

mWebView2.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/*");  
    MyAwesomeActivity.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);       
    }  
});  

Note: The exact parameters for this function have changed throughout the various versions of Android. For a solution which works across all Android versions, check out this question, or try using the parameters listed in this answer.

Community
  • 1
  • 1
David
  • 1,698
  • 16
  • 27
  • In my aspx page it collects information for registering and submits it to a database. I want to make that aspx page work not open a file upload ouside of that webview. – CsharpBeginner Sep 27 '12 at 02:33
  • How would i implement that code into my code above. take your function and put it in my first case statement? – CsharpBeginner Oct 01 '12 at 18:00
  • You probably don't need the startActivityForResult(). Just make that startActivity(Intent...) – David Oct 08 '12 at 11:11
  • @David could you edit your answer to either link to or add methods [from this post](http://stackoverflow.com/questions/10953957/webview-android-4-0-file-upload) as a lot of questions seem to redirect to your question – vamsiampolu Feb 21 '14 at 09:13
  • @user2309862 I've updated the answer with those links you suggested. – David Mar 23 '14 at 12:59