Skip to content

isAndroid ​

isAndroid is a utility function that detects whether the current device is running Android.

Notes:

  • All Android browsers include the token "Android" in the user agent.

Interface ​

ts
function isAndroid(userAgent?: string): boolean;

Parameters ​

  • userAgentstring

    Optional user agent string to check. Defaults to navigator.userAgent.

Return Value ​

  • boolean

    true if the device is running Android, false otherwise. Returns false on server-side rendering environments.

Example ​

tsx
if (isAndroid()) {
  // Android-specific code
  enableAndroidOptimizations();
}
tsx
// With custom user agent
const isAndroidDevice = isAndroid(
  'Mozilla/5.0 (Linux; Android 12; Pixel 6) Chrome/120'
);

Released under the MIT License.