WebView Download HTML not working

Possible duplicate:
Upload files to WebView

Hope there is a simple answer to this question. I have this Android code working in my application:

package com.example.myfirstapp; import android.webkit.WebViewClient; import android.webkit.WebView; import android.util.Log; public class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); Log.d ("myfirstapp_tag", "shouldOver... loaded Url " + url ); return true; } } 

... but when this HTML is loaded ...

 <tr><td> <form method="post" action="/myphp.php" enctype="multipart/form-data"> <label for="upload">Add Pic:</label><input type="file" name="file" id="file" /> <input type="hidden" name="action" value="upload" /> <input type="submit" name="submit" value="Upload" /> </form> </td></tr> 

... the form is displayed with the "Select File" button, but when I click on it, nothing happens. What am I doing wrong here?

thanks

+4
source share
1 answer

I found the answer here on stackoverflow, but lost the link, so here is what I needed to do ...

In my MainActivity class, I do this ...

 ... import android.webkit.ValueCallback; import android.net.Uri; public class MainActivity extends Activity { ... 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; } } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); WebView webView = (WebView) findViewById(R.id.webview); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new MyWebViewClient()); webView.setWebChromeClient( new WebChromeClient() { @SuppressWarnings("unused") public void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Log.d ("myfirstapp_tag", "1) MainActivity.java loaded openFileChooser" ); Intent i = new Intent(Intent.ACTION_GET_CONTENT); Log.d ("myfirstapp_tag", "2) MainActivity.java loaded openFileChooser" ); i.addCategory(Intent.CATEGORY_OPENABLE); Log.d ("myfirstapp_tag", "3) MainActivity.java loaded openFileChooser" ); i.setType("image/*"); Log.d ("myfirstapp_tag", "4) MainActivity.java loaded openFileChooser" ); MainActivity.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE); Log.d ("myfirstapp_tag", "5) MainActivity.java loaded openFileChooser" ); } } ); webView.loadUrl("http://example.com/EZC.php"); setContentView(webView); Log.d ("myfirstapp_tag", "MainActivity.java loaded URL and set Content View." ); } } 
+2
source

Source: https://habr.com/ru/post/1434501/


All Articles