We realize that on Android devices, when uploading images, videos and sounds with third-party modules, not work fine.
We have been investigating, and it seems that when a third module integrates and shown by WebView in Android, by default, is not allowed.
To solve this, we found a set of instructions that fix this, and after adding the code, if it allows you to upload images, media ...
If someone wants to contribute something more concepts or ideas, Or correct some of the code that I have put down, are welcome. thanks
--------------------------
Code -->In WebPageActivity.java file, add:
1-
import android.webkit.ValueCallback;
2-Inside the function "publicclass WebPageActivity extends ActivityBase" Add:
private ValueCallback<Uri> mUploadMessage;
privatefinalstaticintFILECHOOSER_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;
}
}
2.1. Inside "publicvoid onCreate(Bundle savedInstanceState)", Add:
m_viewWeb = new WebView(this);
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
WebPageActivity.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("*/*");
WebPageActivity.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("*/*");
WebPageActivity.this.startActivityForResult(
Intent.createChooser(i, "File Chooser"),
WebPageActivity.FILECHOOSER_RESULTCODE);
}
-----------------------