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

    if the device is running Android, false otherwise. Returns false on server


Example

tsx
if (isAndroid()) {
  // Android-specific code
  enableAndroidOptimizations();
}

// With custom user agent
const isAndroidDevice = isAndroid(
  'Mozilla/5.0 (Linux; Android 12; Pixel 6) Chrome/120'
);

基于 MIT 许可证发布。