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 capt
I think a better solution would be to actually prevent using the UI thread, instead of disabling the Thread Checking.
I solved it like this:
private JSONObject createMediaFile(final Uri data) {
Future result = cordova.getThreadPool().submit(new Callable()
{
@Override
public JSONObject call() throws Exception
{
File fp = webView.getResourceApi().mapUriToFile(data);
JSONObject obj = new JSONObject();
try {
// File properties
obj.put("name", fp.getName());
obj.put("fullPath", fp.toURI().toString());
// Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files
// are reported as video/3gpp. I'm doing this hacky check of the URI to see if it
// is stored in the audio or video content store.
if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
if (data.toString().contains("/audio/")) {
obj.put("type", AUDIO_3GPP);
} else {
obj.put("type", VIDEO_3GPP);
}
} else {
obj.put("type", FileHelper.getMimeType(Uri.fromFile(fp), cordova));
}
obj.put("lastModifiedDate", fp.lastModified());
obj.put("size", fp.length());
} catch (JSONException e) {
// this will never happen
e.printStackTrace();
}
return obj;
}
});
try
{
return result.get();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
catch (ExecutionException e)
{
e.printStackTrace();
}
return null;
I wrapped the default method in a callable inner class. Now it gets executed in another thread.