Answer the question
In order to leave comments, you need to log in
The file manager does not open when clicking on input type file in WebView. What can be done?
There is a small application and in one position a form is loaded from the site. All fields except the file are filled in and sent correctly. When you click on the file selection from the application, there is no reaction at all.
Here is the code that loads the content from the site:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView = new WebView(this);
WebSettings webSettings = myWebView.getSettings();
myWebView.setWebViewClient(new WebViewClient());
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl(mUrl);
Answer the question
In order to leave comments, you need to log in
Is the file input (selection) field written in JS? If possible, please provide a link to the form itself.
PS Bucket loves to surprise. Just in case, check the presence in your manifest Uses Permission = android.permission.INTERNET on the Permissions tab, that the system gave the application access to the Internet. The page can be displayed without this condition, but will the scripts work
?
I 'll leave the code here, maybe it will come in handy for someone else, I found it on a bourgeois forum:
Not suitable for 4.4
public class Web extends Activity {
WebView web;
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;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
Intent intent = getIntent();
String mUrl = intent.getStringExtra("nameUrl"); // требуемый урл
String mTitle = intent.getStringExtra("conTitle"); // заголовок активити
if(mTitle!="") {
setTitle(mTitle);
}
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView = new WebView(this);
WebSettings webSettings = myWebView.getSettings();
webSettings.setAllowFileAccess(true);
//webSettings.setBlockNetworkLoads(true);
webSettings.setLoadWithOverviewMode(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadDataWithBaseURL(INPUT_SERVICE, null, null, null, null);
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl(mUrl);
myWebView.setWebChromeClient(new WebChromeClient()
{
//The undocumented magic method override
//Eclipse will swear at you if you try to put @Override here
// For Android 3.0+
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
Web.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);
}
// For Android 3.0+
public void openFileChooser( ValueCallback uploadMsg, String acceptType ) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
Web.this.startActivityForResult(
Intent.createChooser(i, "File Browser"),
FILECHOOSER_RESULTCODE);
}
//For Android 4.1
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
Web.this.startActivityForResult( Intent.createChooser( i, "File Chooser" ), Web.FILECHOOSER_RESULTCODE );
}
});
setContentView(myWebView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.web, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question