cordova-plugin-camera 在 Crosswalk Android 上不工作(在 iOS 上工作)
cordova-plugin-camera not working on Crosswalk Android (Works on iOS)
我有一个离子 (cordova/phonegap) 应用程序,其中包括上传从设备相机或照片库拍摄的照片。我正在通过 ngCordova 使用 cordova 插件,包括 cordova-plugin-camera
和 cordova-plugin-file
.
android版本使用CrossWalk引擎。
我可以 select 从库中获取图像或拍摄新照片。但是我的回调没有被调用所以我无法使用结果。 N.B:在 iOS.
上一切正常
回调(未调用如下)
回调在 'then' 方法中。
$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
};
我需要帮助让它在 Android 上运行。
我已经在模拟器和真实设备上进行了测试。
科尔多瓦版本:5.4.1
模拟器logcat输出如下:
--------- 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.
你好,我已经找到了解决我自己问题的方法 - 以防有人遇到同样的问题。
基本上 Android 上 cordova-plugin-camera
的问题是,一旦相机 activity 被实例化,垃圾收集器就会杀死主应用程序,因此一旦应用程序被实例化,回调就不会发生re-instantiated。解决方案是 运行 CameraPlugin 在前台而不杀死原始应用程序。
我没有自己编写解决方案:这里有一些您可以使用的插件:
我有一个离子 (cordova/phonegap) 应用程序,其中包括上传从设备相机或照片库拍摄的照片。我正在通过 ngCordova 使用 cordova 插件,包括 cordova-plugin-camera
和 cordova-plugin-file
.
android版本使用CrossWalk引擎。
我可以 select 从库中获取图像或拍摄新照片。但是我的回调没有被调用所以我无法使用结果。 N.B:在 iOS.
上一切正常回调(未调用如下) 回调在 'then' 方法中。
$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
};
我需要帮助让它在 Android 上运行。
我已经在模拟器和真实设备上进行了测试。
科尔多瓦版本:5.4.1
模拟器logcat输出如下:
--------- 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.
你好,我已经找到了解决我自己问题的方法 - 以防有人遇到同样的问题。
基本上 Android 上 cordova-plugin-camera
的问题是,一旦相机 activity 被实例化,垃圾收集器就会杀死主应用程序,因此一旦应用程序被实例化,回调就不会发生re-instantiated。解决方案是 运行 CameraPlugin 在前台而不杀死原始应用程序。
我没有自己编写解决方案:这里有一些您可以使用的插件: