I have this code to detect the kind of app where I’m running my Android app (desktop, tablet, and phone):
var deviceDetector = (function() {
var userAgent = navigator.userAgent.toLowerCase();
var detectDevice = function(ua) {
ua = ua.toLowerCase();
// Check for ChromeOS specifically
if (/cros/.test(ua)) {
return "desktop";
}
// Check for Android TV specifically
if (/android.*tv/.test(ua)) {
return "desktop";
}
// Check for tablets
if (/ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP)))/.test(ua)) {
return "tablet";
}
// Check for phones
if (/mobi|ipod|phone|blackberry|opera mini|fennec|minimo|symbian|psp|nintendo ds|archos|skyfire|puffin|blazer|bolt|gobrowser|iris|maemo|semc|teashark|uzard/.test(ua)) {
return "phone";
}
// Default to desktop
return "desktop";
};
var detectedDevice = detectDevice(userAgent);
return {
device: detectedDevice,
detect: detectDevice,
isMobile: detectedDevice !== "desktop",
userAgent: userAgent
};
})();
However, it doesn’t work as expected since in Chromebooks instead of showing the Tablet or Desktop UI, it always displays the Android Mobile one. The app still works and it’s fine, but for the landscape, it loses its main advantages. Do you have any idea how I can fix it? My app is a hybrid app that mixes a Webview with native components, that’s why Ì care about the user agent.
Note:
I already tried to contact the Chromium OS forum without any replies: https://groups.google.com/a/chromium.org/g/chromium-os-discuss