This is piece of code for File Upload in WebView-Android. This returns null for ICS and JB. File Chooser opens after selecting file activity crashes. What could be the problem? What should be code for KK? (Referred from GitHub(@GauntFace).
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
Uri[] results = null;
// Check that the response is a good one
if (resultCode == Activity.RESULT_OK) {
if (intent == null) {
// If there is not data, then we may have taken a photo
if (mCameraPhotoPath == null) {
results = new Uri[] {
Uri.parse(mCameraPhotoPath)
};
}
} else {
String dataString = intent.getDataString();
if (dataString != null) {
results = new Uri[] {
Uri.parse(dataString)
};
}
}
}
mFilePathCallback.onReceiveValue(results);
mFilePathCallback = null;
}
Following is code for openFileChooser:
webView.setWebChromeClient(new WebChromeClient() {
// For Android 3.0+, ICS 4.0
public void openFileChooser(ValueCallback uploadMsg, String acceptType) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
Upload.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), Upload.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.setType("*/*");
Upload.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), Upload.FILECHOOSER_RESULTCODE);
}
// For Android 4.1+ (different params)
public void openFileChooser(ValueCallback < Uri > uploadMsg) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
Upload.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), Upload.FILECHOOSER_RESULTCODE);
}
}
}
0 comments:
Post a Comment