如何在 React-Native 中获取 Android 版本号? (不是API级数)

How to get Android Version number in React-Native? (not API level number)

我想在我的应用程序中显示 Android 版本(例如 8.0、9.0...)。现在我正在使用: Platform.Version 但是这个 returns API 版本 (24, 25...).

我想要一个比仅仅创建映射更优雅的选项,并且不需要每次有新的 android 版本时都重新发布。 有没有办法在没有外部库的情况下做到这一点?

你可以使用这个库,

react-native-device-info

import DeviceInfo from "react-native-device-info";
DeviceInfo.getSystemVersion()

除了版本之外,它还有很多方法可以方便地获取设备特定信息。

编辑:它是getSystemVersion()

您有 2 个选择

  1. 您使用 Platform.Version 获得的地图值具有适当的版本号。
  2. 例如使用第 3 方库 react-native-device-info, getSystemVersion

    DeviceInfo.getSystemVersion()
    

你好检查这个组件

react-native-device-info

check

**Gets the API level.**

**Examples**


getAPILevel()

const apiLevel = DeviceInfo.getAPILevel();

// iOS: ?
// Android: 25
// Windows: ?

您可以使用Platform.constants.Release

你可以:

import { Platform } from 'react-native';

const OsVer = Platform.constants['Release'];