如何在 Phonegap 中找到 Android 平板电脑或手机?

How to find Android tablet or mobile in Phonegap?

我需要设置 android 设备智能 phone 仅肖像? window.isTablet只能找到手机或平板,所以我需要设置屏幕锁定方向并编写代码。

如果你想允许potrait模式,那么添加-

<platform name="android">
    <preference name="Orientation" value="portrait" />
    <allow-intent href="market:*" />
</platform>

在项目文件夹 config.xml<widget> 标签内。

考虑到这个Cordova Device插件,您可能找不到Tablet or Mobile version

可以获得以下properties-

  • device.cordova //version of Cordova running on the device.
  • device.model //name of the device's model or product
  • device.platform //device's operating system name
  • device.uuid
  • device.version
  • device.manufacturer //the device's manufacturer.
  • device.isVirtual //device is virtual(emulated) or real
  • device.serial

使用 Cordova Screen Orientation Plugin 我们修复了。

在app.js

document.addEventListener("deviceready", function() {
    if (window.innerHeight <= 736 || window.innerWidth <= 736) {
        screen.orientation.lock('portrait');
    } else {
        screen.orientation.unlock('portrait');
    }
});

window.addEventListener("orientationchange", function() {
    if (window.innerHeight <= 736 || window.innerWidth <= 736) {
        screen.orientation.lock('portrait');
    } else {
        screen.orientation.unlock('portrait');
    }
});

使用下面的代码,

document.addEventListener("deviceready", function() {
if (window.innerHeight <= 736 || window.innerWidth <= 736) {
    screen.orientation.lock('portrait');
} else {
    screen.orientation.unlock('portrait');
}
});