I've made a relatively simple phonegap app, with the ability to capture images and videos and upload them to a server.
Images work fine, however when I call to capture video the camera UI appears, and when I accept the video the app crashes out with this error in logcat:
java.lang.RuntimeException: Failure delivering result ResultInfo(who=null, request=2, result=-1, data=Intent { dat=content://media/external/video/media/46536 }} to activity {myApp.test.app}: java.lang.IllegalStateException:Do not perform IO operations on the UI thread. Use CordovaInterface.getThreadPool() instead
I'm using phonegap 3.0.0, I've installed the correct plugins via the commandline interface, and my AndroidManifest is fine.
I'm using the demo code from the phonegap API, so the problem isn't there either.
A workaround for this issue is to edit [yourApp]\plugins\org.apache.cordova.media-capture\src\android\Capture.java
Starting at line 377, change this code
private JSONObject createMediaFile(Uri data) {
File fp = webView.getResourceApi().mapUriToFile(data);
JSONObject obj = new JSONObject();
to the following code
private JSONObject createMediaFile(Uri data) {
// is thread checking enabled?
boolean thC = webView.getResourceApi().isThreadCheckingEnabled();
// set thread checking to disabled (this works around mapUriToFile failing with IllegalStateException: Do not perform IO operations on the UI thread.
webView.getResourceApi().setThreadCheckingEnabled(false);
File fp = webView.getResourceApi().mapUriToFile(data);
// set thread checking back to whatever it was before the call above.
webView.getResourceApi().setThreadCheckingEnabled(thC);
JSONObject obj = new JSONObject();
This worked for us, hopefully it will be fixed properly soon.
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