I have an ionic (cordova/phonegap) app that includes uploading pictures taken from the device camera or photo library. I'm using cordova plugins via ngCordova including cordova-plugin-camera
and cordova-plugin-file
.
The android version uses the CrossWalk engine.
I am able to select the image from the library or take a new picture. However my callback isn't called so I'm unable to use the result. N.B: everything works perfectly on iOS.
The callback (which is not called is as follows) The callbacks are in the 'then' methods.
$scope.getPhoto = function(useLibarary) {
var options = {
destinationType: Camera.DestinationType.FILE_URI,
sourceType: (useLibarary) ? Camera.PictureSourceType.PHOTOLIBRARY : Camera.PictureSourceType.Camera,
encodingType: Camera.EncodingType.JPEG
};
$cordovaCamera.getPicture(options).then(function(imageURI) {
// success
//
$scope.postImageSrc = imageURI;
console.log(JSON.stringify(imageURI));
$scope.imageURI = imageURI;
}, function(err) {
// error
console.log("error: " + JSON.stringify(err));
});
$cordovaCamera.cleanup().then(
function() {
console.log("cleanup done");
}); // only for FILE_URI
};
I need help getting getting it to work on Android.
I've tested on emulators and real devices.
Cordova version: 5.4.1
The emulator logcat output is below:
--------- beginning of main
W/BindingManager( 2653): Cannot call determinedVisibility() - never saw a connection for the pid: 2653
--------- beginning of system
I/ActivityManager( 339): START u0 {act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras)} from uid 10057 on display 0
W/PluginManager( 2653): THREAD WARNING: exec() call to Camera.takePicture blocked the main thread for 264ms. Plugin should use CordovaInterface.getThreadPool().
D/ResolverActivity( 2562): sinceTime=1448829119611
I/ActivityManager( 339): START u0 {act=android.intent.action.GET_CONTENT cat=[android.intent.category.OPENABLE] typ=image/* flg=0x3000000 cmp=com.android.documentsui/.DocumentsActivity} from uid 10057 on display 0
W/EGL_emulation( 1929): eglSurfaceAttrib not implemented
W/OpenGLRenderer( 1929): Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6742220, error=EGL_SUCCESS
I/Choreographer( 1929): Skipped 85 frames! The application may be doing too much work on its main thread.
I/UsageStatsService( 339): User[0] Flushing usage stats to disk
I/ActivityManager( 339): Displayed com.android.documentsui/.DocumentsActivity: +5s48ms (total +5s807ms)
I/Choreographer( 1929): Skipped 122 frames! The application may be doing too much work on its main thread.
W/IInputConnectionWrapper( 2653): showStatusIcon on inactive InputConnection
W/Documents( 1929): Failed to restore stack: java.io.FileNotFoundException: Failed to find matching root for null
D/Documents( 1929): Current stack:
D/Documents( 1929): * null
D/Documents( 1929): Before filtering 0, after 0
D/Documents( 1929): Before filtering 1, after 1
D/Documents( 1929): Found 2 of 2 recent queries done
I/art ( 1929): Background partial concurrent mark sweep GC freed 1027(62KB) AllocSpace objects, 0(0B) LOS objects, 40% free, 1752KB/2MB, paused 3.258ms total 114.968ms
W/AudioTrack( 339): AUDIO_OUTPUT_FLAG_FAST denied by client
D/Documents( 1929): onFinished() [content://com.android.providers.media.documents/document/image%3A25]
D/CordovaInterfaceImpl( 2653): Sending activity result to plugin
W/CordovaPlugin( 2653): Attempted to send a second callback for ID: Camera1798864042
W/CordovaPlugin( 2653): Result was: "content:\/\/com.android.providers.media.documents\/document\/image%3A25"
W/art ( 2653): Attempt to remove local handle scope entry from IRT, ignoring
W/EGL_emulation( 2653): eglSurfaceAttrib not implemented
W/OpenGLRenderer( 2653): Failed to set EGL_SWAP_BEHAVIOR on surface 0xa00b1e20, error=EGL_SUCCESS
E/chromium( 2653): [ERROR:buffer_manager.cc(340)] [GroupMarkerNotSet(crbug.com/242999)!:7C04DEA1]GL ERROR :GL_INVALID_OPERATION : glBufferData: <- error from previous GL command
I/Choreographer( 339): Skipped 38 frames! The application may be doing too much work on its main thread.
I/art ( 1929): Explicit concurrent mark sweep GC freed 3277(230KB) AllocSpace objects, 0(0B) LOS objects, 24% free, 1554KB/2MB, paused 1.064ms total 312.134ms
I/art ( 1929): Explicit concurrent mark sweep GC freed 701(63KB) AllocSpace objects, 3(68KB) LOS objects, 26% free, 1423KB/1935KB, paused 2.203ms total 296.900ms
I/art ( 1929): Explicit concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 26% free, 1423KB/1935KB, paused 1.873ms total 404.704ms
E/StrictMode( 1929): class com.android.documentsui.DocumentsActivity; instances=2; limit=1
E/StrictMode( 1929): android.os.StrictMode$InstanceCountViolation: class com.android.documentsui.DocumentsActivity; instances=2; limit=1
E/StrictMode( 1929): at android.os.StrictMode.setClassInstanceLimit(StrictMode.java:1)
I/Choreographer( 1929): Skipped 157 frames! The application may be doing too much work on its main thread.