android - PhoneGap navigator.camera.getPicture 不触发回调

标签 android ios cordova camera

我的 PhoneGap 应用程序中有一个简单的链接,它会触发以下方法:

        navigator.camera.getPicture(function(imageData) {
            console.log('Success');
            $('#image').attr('src', "data:image/jpeg;base64," + imageData);
        }, function(errorMsg) {
            console.log('Error');
        }, {
            quality: 30,
            destinationType: Camera.DestinationType.DATA_URL,
            correctOrientation: true
        }); 

在 iPhone 和 iPad 上它有 70-80% 的时间工作:如果用户点击,相机打开,我拍照,相机关闭,成功方法中的 console.log() 将被触发我可以捕捉图像源。另一次什么都没有发生。将调用成功回调或错误回调。相机打开,我拍照,相机将关闭,我看到我的应用程序,但没有任何反应。我无法找出问题所在。

为了防止存储问题,我在每次单击链接时触发 navigator.camera.cleanup() 方法。但问题仍然存在。在 iPhone、iPad 和我的 Android 模拟器上。首先,我以为我的应用程序会在拍照后自动重启,但这并没有发生(如果设备就绪事件正在发生,我会生成一个 console.log)。

我不认为这是 Android 或 iOS 的问题...但我不知道。

最佳答案

确保在 onDeviceReady 中调用它

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
    your code here!
}

关于android - PhoneGap navigator.camera.getPicture 不触发回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12920289/

相关文章:

android - 为什么一个 ListView 中的数据集显示在另一个 ListView 中?

android - 使用 ViewPager2 将方向更改为横向时显示两 block fragment

ios - 类似于 CGPoint 的类,但带有整数(用于表示网格中的位置)

ios - 我可以在没有 Apple Developer Program 的情况下在我的 iOS 设备上测试我的 Ionic 应用程序吗

ios - 无法使用远程代理 : CordovaModuleLoadError 将 Visual Studio Cordova 应用程序部署到 iPhone

android - 运行 "cordova build android"- 无法找到属性 android :fontVariationSettings and android:ttcIndex

android - Android 11 上的 WebView - 不显示本地镜像文件

android - 设置/更改更改 Android 中的 WebView 用户代理

ios - 如何使用 Xcode 9 添加 gitLab 存储库?

iphone - 解码 URLEncoded 非标准字符