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

时间:2019-04-17 06:33:57

标签: javascript reactjs react-native native

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

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

5 个答案:

答案 0 :(得分:2)

您可以使用此库,

react-native-device-info

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

除版本外,它还有许多方法,对于获取设备特定的信息非常方便。

编辑:它是getSystemVersion()

答案 1 :(得分:2)

你可以:

import { Platform } from 'react-native';

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

答案 2 :(得分:1)

您有2个选择

  1. 使用适当的版本号映射使用Platform.Version获得的值。
  2. 使用第三方库,例如react-native-device-infogetSystemVersion

    DeviceInfo.getSystemVersion()
    

答案 3 :(得分:1)

您可以使用 Platform.constants.Release

答案 4 :(得分:0)

您好,请检查此组件

  

react-native-device-info

check

**Gets the API level.**

**Examples**


getAPILevel()

const apiLevel = DeviceInfo.getAPILevel();

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