Claes Gustavsson
Claes Gustavsson

Reputation: 5689

check if android version is less than 4 with phonegap?

Im trying to check if the android version is less than 4 with phonegap.

Im getting the version with this.

   var deviceOS  = device.platform;  //fetch the device operating system
   var deviceOSVersion = device.version;  //fetch the device OS version
          alert("Device OS: " + deviceOS); 
          alert("Device OS Version: " + deviceOSVersion);

And trying to check if the version is less than 4 with this, but it is not working?

if (deviceOSVersion < 4) {
    alert("android less than 4");
}

I have tested a few thing but no luck.
Any input appreciated thanks.

UPDATE: Im trying to set the last code "useAnimations:animationen" to false if it is and android less than 4 and if it is an iPhone the "animationen" should be true. But on the iPhone it is false with the below code?

 var int = 0;
    var animationen='';

  function onBodyLoad()
        {         
       document.addEventListener("deviceready", onDeviceReady, false);
        }

        function onDeviceReady()
        {
    getDeviceProperty();
        }

    function getDeviceProperty(){
     var deviceOS  = device.platform;  //fetch the device operating system
     var deviceOSVersion = device.version;  //fetch the device OS version
          alert("Device OS: " + deviceOS); 
          alert("Device OS Version: " + deviceOSVersion); 


if (deviceOS.indexOf('Android') >= 0) {
alert("its an android");
int = parseInt(deviceOSVersion);
if(int<4){
alert("animation false");
animationen=false;
}
alert("apptype = android");
}
else
{
alert("apptype = iphone");
animationen=true;
}                     
}


var jQT = new $.jQTouch({
useAnimations: animationen
});

Upvotes: 4

Views: 6625

Answers (2)

John Snau
John Snau

Reputation: 341

var int = 0;  
....// your code here
int = parseInt(deviceOSVersion);
if(int<4){
//do something
}

I've checked and it's working.

Upvotes: 1

SHANK
SHANK

Reputation: 2958

You need to parseInt the value received by using,

if( parseInt( deviceOSVersion, 10 ) < 4 )
{
    // your code
}

Hope that helps

Upvotes: 6

Related Questions