Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap video capture crashes

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.

like image 550
Richard Avatar asked Dec 07 '22 05:12

Richard


1 Answers

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.

like image 136
user2863890 Avatar answered Dec 20 '22 08:12

user2863890