PhoneGap的Andr​​oid上window.device未定义未定义、Andr、PhoneGap、oid

2023-09-06 05:38:41 作者:我跟你很熟吗`)

看来,设备对象在Android不确定。它是在模拟器中,iOS设备与功放定义; iPhone模拟器

It seems that the device object is undefined on Android. It is defined in the simulator, the iOS device & iOS simulator

很显然,我检查看window.device(并试图Window.device,window.Device等的所有变体),并始终得到不确定的 - 但只有一个真正的Andr​​oid设备上。它适用于所有其他情况正常。

Obviously I'm checking to see the window.device (and tried all variants of Window.device, window.Device, etc.), and always getting undefined -- but only on a real Android device. It works fine on all other scenarios.

请帮忙。

推荐答案

当你想使用window.device?

When are you trying to use window.device?

我发现,在Android上,当ondeviceready被解雇了window.device变量尚未公布。

I found that on Android when "ondeviceready" is fired the window.device variable isn't available yet.

所以我做了什么后,ondeviceready设为1秒的超时被触发,然后做一切我想做的东西。

So what I did was set a timeout of 1 second after "ondeviceready" is fired and then do all the stuff I want to do.