as

Settings
Sign out
Notifications
Alexa
亚马逊应用商店
AWS
文档
Support
Contact Us
My Cases
新手入门
设计和开发
应用发布
参考
支持

expo-device

expo-device

@amazon-devices/expo-device提供对有关物理设备的系统信息的访问,例如其制造商和型号。

安装

  1. package.json文件中添加JavaScript库依赖项。

    已复制到剪贴板。

     dependencies: {
         ...
         "@amazon-devices/expo-device": "~2.0.0",
     }
    
  2. 使用npm install命令重新安装依赖项。
  3. 运行kepler build命令。

示例

已复制到剪贴板。

import React, {useEffect, useState} from 'react';
import {StyleSheet, View, Text} from 'react-native';
import * as Device from '@amazon-devices/expo-device';

export const App = () => {
  const [deviceType, setDeviceType] = useState<Device.DeviceType>();
  const [uptime, setUptime] = useState<number>();

  useEffect(() => {
    Device.getDeviceTypeAsync().then(setDeviceType);
    Device.getUptimeAsync().then(setUptime);
  }, []);

  return (
    <View style={styles.container}>
      <Text style={styles.text}>manufacturer: {Device.manufacturer}</Text>
      <Text style={styles.text}>modelName: {Device.modelName}</Text>
      <Text style={styles.text}>
        is TV: {String(deviceType === Device.DeviceType.TV)}
      </Text>
      <Text style={styles.text}>uptime: {uptime}</Text>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'white',
    justifyContent: 'center',
    alignItems: 'center',
  },
  text: {
    fontSize: 30,
    color: 'black',
  },
});

API参考

请您查看以下专门文档页面,了解有关此库、API参考等的信息: 针对expo-device的官方Expo文档(仅提供英文版)。

常量

名称 类型 描述
Device.brand string | null 设备品牌。产品/硬件的消费者可见品牌。在网页和Vega上,此值始终为null。
Device.designName string | null 工业设计的具体配置或名称。它代表了设备从制造期间的设计到批量生产的名称。在网页和Vega上,此值始终为null。
Device.deviceName string | null 设备的人类可读名称,可以由设备的用户设置。如果设备名称不可用,尤其是在网页或Vega上,则此值为null。
Device.deviceType DeviceType | null 设备类型为DeviceType枚举值。
Device.deviceYearClass number | null 此设备的设备年龄级。在网页和Vega上,此值始终为null。
Device.manufacturer string | null 产品或硬件的实际设备制造商。如果无法确定,则此字段的该值可能为null。
Device.modelName string | null 设备型号的人类易记型名称。这是人们通常用来指代设备的名称,而不是编程模型标识符。如果无法确定,则此字段的该值可能为null。
Device.osBuildFingerprint string | null 一种唯一标识当前正在运行的系统操作系统内部版本的字符串。
Device.osBuildId string | null 操作系统的内部版本ID,用于更精确地标识操作系统版本。在网页上,此值始终为null。
Device.osInternalBuildId string | null 设备上运行的操作系统的内部版本ID。在网页上,此值始终为null。
Device.osName string | null 设备上运行的操作系统的名称。
Device.osVersion string | null 人类可读的操作系统版本字符串。请注意,版本字符串可能并不总是包含由点分隔的三个数字。
Device.productName string | null 设备实现者选择的设备的总体产品名称,其中包含设备的开发名称或代号。对应于Build.PRODUCT。在网页上,此值始终为null。
Device.supportedCpuArchitectures string[] | null 支持的处理器架构版本列表。设备需要其运行的二进制文件能够针对其中一种架构进行编译。如果无法确定支持的架构,尤其是在网页上,则此值为null。
Device.totalMemory number | null 设备的总内存,以字节为单位。这是内核可访问的总内存,但不一定是单个应用可以访问的总内存。这基本上是设备的RAM量,不包括低于内核的固定分配,例如DMA缓冲区、基带CPU的RAM等。在网页和Vega上,此值始终为null。

方法

名称 类型 描述
Device.getDeviceTypeAsync() Promise<DeviceType> 将设备类型作为DeviceType枚举值进行检查。
Device.getUptimeAsync() Promise<number> 获取自设备上次重启以来的正常运行时间,以毫秒为单位。

枚举

DeviceType

名称 值​ 描述
UNKNOWN DeviceType.UNKNOWN = 0 无法识别的设备类型。
PHONE DeviceType.PHONE = 1 移动电话手机,通常带有触摸屏且由一只手握持。
TABLET DeviceType.TABLET = 2 平板电脑,所配触摸屏通常比普通手机大。
DESKTOP DeviceType.DESKTOP = 3 台式电脑或笔记本电脑,通常带有键盘和鼠标。
TV DeviceType.TV = 4 带有基于电视的接口的设备。

错误代码

代码 描述
ERR_DEVICE_ROOT_DETECTION 针对isRootedExperimentalAsync引发的错误代码。如果对某些系统文件没有读取访问权限,则可能会引发此错误代码

实现详情

  • Device.deviceTypeDevice.getDeviceTypeAsync() - 返回UNKNOWNTV
  • Device.totalMemory - returns null

Vega上不支持的API:

  • Device.brand
  • Device.designName
  • Device.deviceName
  • Device.deviceYearClass
  • Device.isRootedExperimentalAsync()

支持的版本

程序包版本 基于 @amazon-devices/react-native-kepler版本
2.0.x 5.8.0 2.0.x

其他资源

有关其他库的信息,请参阅支持的第三方库和服务


Last updated: 2025年9月30日