1

I am trying to upload images via a WebView in Android. The problem is the missing content type. Seems like it`s a known issue in Android 4.4.4. What can be done in this situation? I found this answer on similar question, but I can't figure out how to implement this solution. I have access to server side.

Thanks.

Community
  • 1
  • 1
NEXT
  • 11
  • 1
  • We'll need some more information about why the answer you quoted doesn't work for you. Otherwise your question would be a duplicate of that one. – TAM Apr 14 '16 at 08:09

1 Answers1

0

In the answer you found, they call

startActivityForResult( Intent.createChooser( i, "File Chooser" ), MainActivity.FILECHOOSER_RESULTCODE)

What means, you should get the results of this in this method

  protected void onActivityResult( int requestCode, int resultCode, Intent data )
  {
     if(requestCode == MainActivity.FILECHOOSER_RESULTCODE)
     {
       if(resultCode == RESULT_OK)
         // TODO: Check Results of data-intent
     }
  }

in this method you can handle the results from the file chooser and do a upload by yourself (e.g. with URLConnection or ApacheHttpClient).

UPDATE 2016-10-19

Here is a Example where the ValueCallback is stored and the result of the ChooserIntent is passed back to the callback. I didn`t try this example, but I think it should trigger a own upload methode from the webview.

  private ValueCallback<Uri> mUploadMessage;
  private Uri mCapturedImageURI = null;

  protected void onActivityResult( int requestCode, int resultCode, Intent data )
  {
     if(requestCode == MainActivity.FILECHOOSER_RESULTCODE)
     {
       if(resultCode == RESULT_OK) {
          result = intent == null ? mCapturedImageURI : intent.getData(); 
          mUploadMessage.onReceiveValue(result);
       }
     }
  }

onReceiveValue(result);

Source: http://androidexample.com/Open_File_Chooser_With_Camera_Option_In_Webview_File_Option/index.php?view=article_discription&aid=128

Check this thread for more examples https://stackoverflow.com/a/7857102/2377961

Community
  • 1
  • 1
Radon8472
  • 4,285
  • 1
  • 33
  • 41