I have an webview with file chooser which is works in Samsung Galaxy Tab 2(Android 4.1.1), Lenovo, Nexus Tablets
. But the problem is it is not woking in Samsung galaxy Tab 3
. Which is the Android 4.4 tablet
. I added my setWebChromeClient
code here. Can you Please someone help me.
// implement WebChromeClient inner class
// we will define openFileChooser for select file from camera
webView.setWebChromeClient(new WebChromeClient() {
// openFileChooser for Android 3.0+
public void openFileChooser(ValueCallback<Uri> uploadMsg,
String acceptType) {
/** updated, out of the IF **/
mUploadMessage = uploadMsg;
/** updated, out of the IF **/
Log.e("Reac", "**Here");
try {
File imageStorageDir = new File(base_directory,
"profile_pictures");
if (!imageStorageDir.exists()) {
imageStorageDir.mkdirs();
}
src_file = new File(imageStorageDir + File.separator
+ "IMG_" + child_id + ".jpg");
mCapturedImageURI = Uri.fromFile(src_file); // save to the
// private
// variable
final Intent captureIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
mCapturedImageURI);
startActivityForResult(captureIntent,
FILECHOOSER_RESULTCODE);
} catch (Exception e) {
Toast.makeText(getBaseContext(), "Camera Exception:" + e,
Toast.LENGTH_LONG).show();
}
}
// openFileChooser for Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
openFileChooser(uploadMsg, "");
}
// openFileChooser for other Android versions
public void openFileChooser(ValueCallback<Uri> uploadMsg,
String acceptType, String capture) {
openFileChooser(uploadMsg, acceptType);
}
/** Added code to clarify chooser. **/
// The webPage has 2 filechoosers and will send a console message
// informing what action to perform, taking a photo or updating the
// file
public boolean onConsoleMessage(ConsoleMessage cm) {
onConsoleMessage(cm.message(), cm.lineNumber(), cm.sourceId());
return true;
}
public void onConsoleMessage(String message, int lineNumber,
String sourceID) {
// Log.d("androidruntime", "Per cÔøΩnsola: " + message);
}
/** Added code to clarify chooser. **/
});
I added only piece of code. Please ask me if any details required.
It's the end of the road for the Samsung Galaxy S7 active and the old Galaxy Tab A 10.1 – at least if you want to continue receiving security updates.
It seems there is a known bug in Android 4.4 that make <input type="file">
not work inside a WebView.
Unfortunately openFileChooser
is not a public API and there is not a public support for that.
In Android Lollipop has been introduced the API onShowFileChooser for this purpose.
My suggest is to workaround the problem using the JavaScript native WebView interface and define a custom openFileChooser API handled by the native part of your App.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With