Question

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. Fix

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.

Any help would be great. Thanks

@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;    

}    
}    

@Override
public boolean onOptionsItemSelected(MenuItem item) {    
    // Handle item selection    
    switch (item.getItemId()) {        
    case R.id.register:            

        wv = new WebView(this);  
        wv.setWebViewClient(new WebViewClient());   
        wv.getSettings().setJavaScriptEnabled(true); 

        wv.loadUrl("http://www.mysite.com/AndroidAddMember.aspx"); 

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

                 }    
        });    
            setContentView(wv);    


                 return true;
    default:            
        return super.onOptionsItemSelected(item);    
        }
}
Was it helpful?

Solution

In reality the webview dont allow to upload a file this way. Either you have to create a upload button in menu of your app. And take the file input and then upload to your website through http .

Or better you should use phonegap to make it possible . In phone gap you can use file uploading and downloading easily.

http://docs.phonegap.com/en/2.1.0/cordova_file_file.md.html#File

Only this way you can upload the file to your server or no way. Webview only provides basic functionality.

you might better use this way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top