I am creating a sample for Worklight Runtime Skins for Android device by referring link "http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v610/05_03_Supporting_multiple_form_factors_using_Worklight_skins.pdf". I have changed JS,CSS and HTML for applying skin on phone/tablet, and the same is tested to work fine via Worklight Preview.
But when I try to run the same code in real device I am not getting proper output as expected. The reason for that is 'getSkinName()' functionality in skinLoader.js is not returning valid result. I tried using following code for detecting if a device is mobile or tablet, but both functions gave invalid outputs.
Detect Device using UserAgent: //Always returns 'android.phone' skin.
function getSkinName() {
var userAgent = navigator.userAgent;
var skinName = "default";
alert(userAgent);
//android tablet
if(userAgent.toLowerCase().indexOf("android") != -1 &&
userAgent.toLowerCase().indexOf("mobile") == -1){
skinName = "default";
alert("tablet!");
}
//android phone
else if(userAgent.toLowerCase().indexOf("android") != -1 &&
userAgent.toLowerCase().indexOf("mobile") != -1){
skinName = "android.phone";
alert("phone!");
}
return skinName;
}
Detect Device using width of device: //Not working properly across orientation
function getSkinName() {
var skinName = "default";
var hres = screen.width || window.innerWidth || 320;
var ratio = window.devicePixelRatio || 1;
if (ratio == 0) {
ratio = 1;
}
var virtWidth = hres / ratio;
if (virtWidth >= 640) {
skinName = "android.tablet";
}
return skinName;
}
Please share thoughts on correcting getSkinName() for proper functioning.