19

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?

7 Answers 7

37

In js you can :

import { Platform } from 'react-native';

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

and in type script:

const OsVer = (Platform.constants as any).Release
Sign up to request clarification or add additional context in comments.

Comments

8

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()

1 Comment

getVerison() does not print the android version itself. It prints the application version.
6

You can use Platform.constants.Release

4 Comments

it has Error : TypeError: undefined is not an object (evaluating '_reactNative.Platform.Constants.Release')
@PurTahan which react native version you are using?
This constant is available only on Android, check docs: reactnative.dev/docs/platform#constants
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#version
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()
    

Comments

2

Use Platform.

import { Platform } from 'react-native';
const version = Platform.Version;

Comments

1

Hi check this component

react-native-device-info

check

**Gets the API level.**

**Examples**


getAPILevel()

const apiLevel = DeviceInfo.getAPILevel();

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.