How to Detect the Device is an Android Device using JavaScript? Last Updated : 08 Oct, 2024 Comments Improve Suggest changes Like Article Like Report Detecting an Android device using JavaScript helps improve web experiences. By checking the user agent string, developers can identify Android devices and apply specific features or styles. This method ensures compatibility and optimizes functionality for different platformsApproachUse the navigator.userAgent property to get the value of the user-agent header sent by the browser to the server.Check the index of 'android' in the userAgent.If the index is greater than -1 then it is Android phone else, not an Android phone.Example 1: This example checks whether the device is an Android phone or not. html <!DOCTYPE HTML> <html> <head> <title> How to detect Android Phone using JavaScript ? </title> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP" style="font-size: 19px; font-weight: bold;"> </p> <button onclick="GFG_Fun()"> click here </button> <p id="GFG_DOWN" style="color: green; font-size: 24px; font-weight: bold;"> </p> <script> let el_up = document.getElementById("GFG_UP"); let el_down = document.getElementById("GFG_DOWN"); el_up.innerHTML = "Click on the button to detect if" + " the device is android phone."; function GFG_Fun() { let res = "Device is not Android Phone"; let userAgent = navigator.userAgent.toLowerCase(); let Android = userAgent.indexOf("android") > -1; if (Android) { res = "Device is Android Phone"; } el_down.innerHTML = res; } </script> </body> </html> Output: Example 2: This example uses retrieves the navigator.userAgent property, checks for 'android' using a regular expression, and determines if the device is an Android phone. html <!DOCTYPE HTML> <html> <head> <title> How to detect Android Phone using JavaScript ? </title> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP" style="font-size: 19px; font-weight: bold;"> </p> <button onclick="GFG_Fun()"> click here </button> <p id="GFG_DOWN" style="color: green; font-size: 24px; font-weight: bold;"> </p> <script> let el_up = document.getElementById("GFG_UP"); let el_down = document.getElementById("GFG_DOWN"); el_up.innerHTML = "Click on the button to detect if" + " the device is android phone."; function GFG_Fun() { let res = "Device is not Android Phone"; let Android = /(android)/i.test(navigator.userAgent); if (Android) { res = "Device is Android Phone"; } el_down.innerHTML = res; } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Detect the Device is an Android Device using JavaScript? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads Detect a device is iOS or not using JavaScript In order to detect a device whether it is iOS or not. We're going to Navigator platform and Navigator userAgent property. Navigator userAgent property This property returns the value of the user-agent header which is sent by the browser to the server. Returned value, have information about the name, 2 min read How to get the Android version of your device using JavaScript? The task is to detect the Android version of the user with the help of JavaScript. Two approaches are discussed here, the first example uses the RegExp and the second uses indexOf method to search the keyword 'android'. Note: Both codes will only work when you run them on Android devices. Approach 1 3 min read How to detect touch screen device using JavaScript? Sometimes you might be looking for some features to include into your web-app that should only be available to devices with a touch screen. You may need this detection while introducing newer smarter controls for touch screen users in the game app or a GPS and navigation application. While there are 3 min read How to detect device and swap the CSS file ? When creating a webpage, the most important thing is the user experience with the frontend, especially the designing part or CSS. For a smooth experience, a frontend developer needs to make the webpage responsive. As "one size doesn't fit all", a single design will not work on all devices. That's wh 2 min read How to detect Adblocker using JavaScript ? In this article, we will be developing an adblocker detector using JavaScript. Adblocker is an extension that is used to block the ads which are served by the website. Adblocker blocks the DOM and the script which has the code to show ads. The adblockers have massive data of blocklist file names and 3 min read How to detect touch screen device using CSS ? In this article, we will learn how to detect touchscreen devices using CSS. In a website, it becomes important to detect the pointing device used by the user. For example, if the user uses a finger as the pointing device (which has less accuracy on the screen due to more screen-finger contact area) 2 min read How to detect the user's device using jQuery ? The task is to determine the user's device, whether it is iPad or not, using JQuery. Below are the required methods: Navigator userAgent Property: This property returns the value of the header of user-agent which is sent by the browser to the server. Returned value, have information like name, versi 1 min read How to detect the user browser ( Safari, Chrome, IE, Firefox and Opera ) using JavaScript ? The browser on which the current page is opening can be checked using JavaScript. The userAgent property of the navigator object is used to return the user-agent header string sent by the browser. This user-agent string contains information about the browser by including certain keywords that may be 4 min read How to detect whether the website is being opened in a mobile device or a desktop in JavaScript ? Using CSS Media Queries, we can easily know which user is currently viewing our website on which device (using min-width and max-width). It is only limited to styling web pages, but we can control the functionality of the website according to the user's device using the navigator userAgent Property 1 min read How to detect the Internet connection is offline or not using JavaScript? Detecting if the internet connection is offline using JavaScript involves utilizing the navigator.onLine property. This property returns false when the browser is offline and true when connected, allowing you to respond to network connectivity changes in real-time.Syntax: function isOnline() { retur 1 min read Like