Santhoshkumar
Santhoshkumar

Reputation: 780

How to find Android tablet or mobile in Phonegap?

I need set android device smart phone portrait only? window.isTablet is find the mobile or tablet only, so I need to set screen lock orientation and write code too.

Upvotes: 2

Views: 1230

Answers (3)

user8591411
user8591411

Reputation:

Use following code,

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

Upvotes: 0

Santhoshkumar
Santhoshkumar

Reputation: 780

Using Cordova Screen Orientation Plugin we fixed.

In 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');
    }
});

Upvotes: 2

pro_cheats
pro_cheats

Reputation: 1582

If you want to allow potrait mode only, then add -

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

inside <widget> tag in config.xml in your project folder.

You may not be able to find Tablet or Mobile version as far as this Cordova Device plugin is considered.

You can get the following 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

Upvotes: 0

Related Questions