Search code examples
cordovaonsen-uiphonegap

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.


Solution

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