Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using the Ubuntu SDK to develop a QML app that runs both on the desktop and on mobile devices. Depending on where it's running on the desktop or on a device, certain behaviours should be different.

What's the recommended way of programmatically detecting whether an app is running on the desktop or on a mobile device?

share|improve this question
    
I think it can be done by checking proess status –  Tachyons Jun 11 '13 at 10:17
add comment

2 Answers

up vote 2 down vote accepted

At the moment the only way to detect it is by checking the Application's width and height. For instance assuming that the phone's widthxheight is 40x71 GU (default portrait), the tablet is 160x100 GU (default landscape), anything that goes above 160x100 GU can be considered as desktop.

There are plans to provide flags to identify for instance whether there is a HW keyboard attached, pointing device, ASO, however those flags should not be used alone to identify a desktop form factor as you can attach mouse/HW keyboard to phone/tablet through bluetooth.

share|improve this answer
    
Thanks! I've also now come to realize another important bit of information: you can set a fixed window size for the desktop, on the phone it automatically opens full-screen –  David Planella Jun 14 '13 at 10:51
add comment

@zsombi so something like this?

MainView {
    id: mainView
    objectName: "mainView"
    applicationName: "myapp"
    automaticOrientation: true
    width:  units.gu(40)
    height: units.gu(71)

    //detect whether an app is running on a mobile device or on the desktop, base on screen-size
    property bool desktop: false;
    function sizeChanged()
    {
        if(mainView.width > units.gu(160) && mainView.height < units.gu(100))
           desktop = true;
        else
            desktop = false;
    }
    onWidthChanged: {
        sizeChanged();
    }
    onHeightChanged: {
        sizeChanged();
    }
}

Then you can make an

if(desktop) 
    //Desktop  
else 
    //mobil 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.