1
I have an Android application consuming a web page and implementing some functionality for the user. The problem appears when I try to attach media files from Android device to send to server more than once; it crashes. The onShowFileChooser() method is only called once and then stops working, I encountered the same problem here and tried to implement all the proposed solutions but could not solve, what I am doing wrong?
Method onShowFileChooser:
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
if(mFilePathCallback != null)
mFilePathCallback.onReceiveValue(null);
mFilePathCallback = filePathCallback;
Log.d("DEBUG", "onShowFileChooser() ACIONADO!");
Intent intent = null;
if (fileChooserParams.getAcceptTypes()[0].contains(IMAGE_TYPE) &&
fileChooserParams.getAcceptTypes()[0].contains(VIDEO_TYPE))
intent = createFileSelectIntent();
else if (fileChooserParams.getAcceptTypes()[0].contains(IMAGE_TYPE))
intent = createPictureIntent();
else if(fileChooserParams.getAcceptTypes()[0].contains(VIDEO_TYPE))
intent = createVideoIntent();
if (intent!=null)
startActivityForResult(intent, INPUT_FILE_REQUEST_CODE);
return true;
}
Method onActivityResult:
@Override
public void onActivityResult (int requestCode, int resultCode, Intent data) {
if(requestCode == INPUT_FILE_REQUEST_CODE) {
if (mFilePathCallback != null) {
Uri[] results = new Uri[]{};
if (resultCode == Activity.RESULT_OK) {
FileBean fileBean = null;
if (data != null && data.getDataString()!=null) {
String dataString = data.getDataString();
Uri uri = Uri.parse(Utils.getRealPath(this, dataString));
fileBean = new FileBean(uri, Utils.getFileType(uri.getPath()));
}
else if (filePath != null)
fileBean = new FileBean(Uri.parse(filePath), Utils.getFileType(filePath));
if (fileBean != null) {
ApplicationStateSingleton.getInstance().getFileBeanList().add(fileBean);
results = new Uri[]{fileBean.getUri()};
}
}
mFilePathCallback.onReceiveValue(results);
mFilePathCallback = null;
return;
}
if (mFilePathCallbackKitKat != null) {
Uri result = null;
if (resultCode == Activity.RESULT_OK) {
FileBean fileBean = null;
if (data != null && data.getDataString()!=null) {
String dataString = data.getDataString();
Uri uri = Uri.parse(Utils.getRealPath(this, dataString));
fileBean = new FileBean(uri, Utils.getFileType(uri.getPath()));
}
else if (filePath != null)
fileBean = new FileBean(Uri.parse(filePath), Utils.getFileType(filePath));
if (fileBean != null) {
ApplicationStateSingleton.getInstance().getFileBeanList().add(fileBean);
result = fileBean.getUri();
}
}
mFilePathCallbackKitKat.onReceiveValue(result);
mFilePathCallbackKitKat = null;
return;
}
}
super.onActivityResult(requestCode, resultCode, data);
}
These are the classes that I think are relevant to solving the problem, but if you need more code fragments, let me know.