【问题标题】:cordova-plugin-camera not working on Crosswalk Android (Works on iOS)cordova-plugin-camera 在 Crosswalk Android 上不起作用(适用于 iOS)
【发布时间】:2015-12-13 20:58:13
【问题描述】:

我有一个 ionic (cordova/phonegap) 应用程序,其中包括上传从设备相机或照片库拍摄的照片。我正在通过 ngCordova 使用 Cordova 插件,包括 cordova-plugin-cameracordova-plugin-file

android版本使用CrossWalk引擎

我可以从库中选择图像或拍摄新照片。但是我的回调没有被调用,所以我无法使用结果。 注意:一切都在 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

emulator 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.

【问题讨论】:

  • 几个问题。你为什么不(首先)使用标准 API 进行测试?你知道 Android 是用 Java 编写的,而 iOS 是用 Objective-C 编写的吗?您是否在 index.html 中使用内联 Javascript?您的所有资产(Javascript、CSS、字体等)都在设备上吗?
  • 谢谢@JesseMonroy650。我正在使用 Cordova 进行跨平台开发,因为我没有时间使用 Java/Obj-C/Swift 进行本机开发 - 无论哪种方式,Cordova 在 Javascript 中都有本机 api 包装器。我的 javascript 包含在我的 index.html 中,并使用 AngularJS 加载。是的,所有资产都在设备上。
  • 好的。看来Java是你的弱点。不幸的是,即使Java/Obj-C/etc 不是必需的,它在您阅读错误日志时也会有所帮助。第二行说W/BindingManager(2653):不能调用determinedVisibility()。这意味着应该解决的事情 - 没有。我建议删除 cordova-plugin-file 来测试您的 camera 代码。你也可以看看我的demo code。它使用Phonegap Build。但是,您也可能遇到whitelist 错误。更多在接下来......
  • 您可能无意中介绍了使用 Cordova whitelist 的必要性,但如果不查看整个代码库,我就无法判断。在任何情况下,您都需要学习如何调试这些问题 - 我给您的方法是我们在所有论坛中反复使用的方法。
  • 再次感谢@JesseMonroy650。我对原生 java android 有很好的了解,但是我认为最好不要更改任何插件代码。我必须使用cordova-plugin-file,因为我需要FILE_URI,以便稍后上传文件。与此同时,我正在查看您的演示代码,看看有什么不同。

标签: android file cordova android-camera crosswalk


【解决方案1】:

您好,我找到了解决我自己问题的方法 - 以防万一有人遇到同样的问题。

Android 上cordova-plugin-camera 的问题基本上是,一旦相机活动被实例化,垃圾收集器就会杀死主应用程序,因此一旦应用程序被重新实例化,回调就不会发生。解决方案是在前台运行 CameraPlugin 而不杀死原始应用程序。

我没有自己编写解决方案:这里有一些你可以使用的插件:

【讨论】:

    猜你喜欢
    • 2017-03-03
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    相关资源
    最近更新 更多