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

7

17

I want to display the Android Version in my app (like 8.0, 9.0...). For now I am using: Platform.Version But this returns the API version (24, 25...).

I would like an option that's more elegant than just creating a mapping, and that does not require republishing every time there is a new android release. Is there a way to do that without an external library?

Leatherback answered 17/4, 2019 at 6:33 Comment(0)
N
33

you can :

import { Platform } from 'react-native';

const OsVer = Platform.constants['Release'];
Neptune answered 11/1, 2021 at 3:57 Comment(0)
E
7

You can use this library,

react-native-device-info

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

apart from version, it has lots of methods which are much handy for getting device specific information.

EDIT: It is getSystemVersion()

Ezequieleziechiele answered 17/4, 2019 at 6:39 Comment(1)
getVerison() does not print the android version itself. It prints the application version.Mairamaire
B
6

You can use Platform.constants.Release

Benefield answered 17/9, 2020 at 7:16 Comment(4)
it has Error : TypeError: undefined is not an object (evaluating '_reactNative.Platform.Constants.Release')Neptune
@Neptune which react native version you are using?Benefield
This constant is available only on Android, check docs: reactnative.dev/docs/platform#constantsTifanytiff
The docs are not consistent on this. This section says that the constant is on both platforms but table at the top of the page says Android only. reactnative.dev/docs/platform#versionMafala
B
3

You have 2 options

  1. Map values you are getting using Platform.Version with appropriate version number.
  2. Use 3rd party library for example react-native-device-info, getSystemVersion

    DeviceInfo.getSystemVersion()
    
Buzzer answered 17/4, 2019 at 6:53 Comment(0)
M
1

Hi check this component

react-native-device-info

check

**Gets the API level.**

**Examples**


getAPILevel()

const apiLevel = DeviceInfo.getAPILevel();

// iOS: ?
// Android: 25
// Windows: ?
Masao answered 17/4, 2019 at 9:1 Comment(0)
A
1

Use Platform.

import { Platform } from 'react-native';
const version = Platform.Version;
Adequacy answered 5/2, 2024 at 21:13 Comment(0)
E
0

I am facing the same issue, but this is not a problem. If you console.log Platform.Version, it will return the target SDK version. With the help of targetSdkVersion, you can determine the device version (e.g., targetSdkVersion = 33 is for Android 13 and above). Alternatively, you can use the react-native-device-info package; it will provide you with the Device OS version directly. you can checkout this also- https://reactnative.dev/docs/platform

Execrate answered 23/11, 2023 at 15:14 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.