Device Information for React Native.
Your iOS Podfile will need to move to an iOS 10 minimum. v7 of this module no longer supports iOS9.
Using npm:
npm install --save react-native-device-info
or using yarn:
yarn add react-native-device-info
If you want to use Install Referrer tracking, you will need to add this config to your Proguard config
-keep class com.android.installreferrer.api.** {
*;
}
If you are experiencing issues with hasGms() on your release apks, please add the following rule to your Proguard config
-keep class com.google.android.gms.common.** {*;}
This module defaults to AndroidX you should configure your library versions similar to this in your android/build.gradle file's "ext" block
Android
...
ext {
// dependency versions
We have 3 options for deviceId:
//Option 1 (latest):
firebaseIidVersion = "19.0.1" // default: "19.0.1"
//Option 2 (legacy GooglePlay dependency but using AndroidX):
googlePlayServicesIidVersion = "17.0.0" // default: "17.0.0" - AndroidX
//Option 3 (legacy GooglePlay dependency before AndroidX):
googlePlayServicesIidVersion = "16.0.1"
// getAppSetId() - optional: set to include play-services-appset (e.g. "16.1.0")
// playServicesAppSetVersion = "16.1.0"
//include as needed:
compileSdkVersion = "28" // default: 28 (28 is required for AndroidX)
targetSdkVersion = "28" // default: 28 (28 is required for AndroidX)
supportLibVersion = '1.0.2' // Use '28.0.0' or don't specify for old libraries, '1.0.2' or similar for AndroidX
mediaCompatVersion = '1.0.1' // Do not specify if using old libraries, specify '1.0.1' or similar for androidx.media:media dependency
supportV4Version = '1.0.0' // Do not specify if using old libraries, specify '1.0.0' or similar for androidx.legacy:legacy-support-v4 dependency
}
...
If you need non-AndroidX you will need to use the jetifier package in reverse mode, documentation available with that package.
Linking in native modules is a frequent source of trouble for new react-native developers, resulting in errors like "RNDeviceInfo is null" etc. For this reason automatic linking was implemented, and it should be used in your project.
Automatic linking is supported for all platforms (even windows on React native >= 0.63!)
Previous versions need to do manual linking. No support is offered for these previous react-native versions but you may refer to older versions of this README if you like. Upgrade to modern versions of react-native. Use upgrade-helper tool on the internet if needed.
import DeviceInfo from 'react-native-device-info';
// or ES6+ destructured imports
import { getUniqueId, getManufacturer } from 'react-native-device-info';
Note that many APIs are platform-specific. If there is no implementation for a platform, then the "default" return values you will receive are "unknown" for string, -1 for number, and false for boolean. Arrays and Objects will be empty ([] and {} respectively).
Most APIs return a Promise but also have a corresponding API with Sync on the end that operates synchronously. For example, you may prefer to call isCameraPresentSync() during your app bootstrap to avoid async calls during the first parts of app startup.
Note about getUserAgentSync
While the asynchronous method getUserAgent is available on both platforms, getUserAgentSync is only supported on Android.
The example app in this repository shows an example usage of every single API, consult the example app if you have questions, and if you think you see a problem make sure you can reproduce it using the example app before reporting it, thank you.
| Method | Return Type | iOS | Android | Windows | Web | visionOS |
|---|---|---|---|---|---|---|
| getAndroidId() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getAppSetId() | Promise<AppSetIdInfo> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getApiLevel() | Promise<number> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getApplicationName() | string |
✅ | ✅ | ✅ | ❌ | ✅ |
| getAvailableLocationProviders() | Promise<Object> |
✅ | ✅ | ❌ | ❌ | ✅ |
| getBaseOs() | Promise<string> |
❌ | ✅ | ✅ | ✅ | ❌ |
| getBuildId() | Promise<string> |
✅ | ✅ | ✅ | ❌ | ✅ |
| getBatteryLevel() | Promise<number> |
✅ | ✅ | ✅ | ✅ | ✅ |
| getBootloader() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getBrand() | string |
✅ | ✅ | ✅ | ❌ | ✅ |
| getBuildNumber() | string |
✅ | ✅ | ✅ | ❌ | ✅ |
| getBundleId() | string |
✅ | ✅ | ✅ | ❌ | ✅ |
| isCameraPresent() | Promise<boolean> |
❌ | ✅ | ✅ | ✅ | ❌ |
| getCarrier() | Promise<string> |
✅ | ✅ | ❌ | ❌ | ❌ |
| getCodename() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getDevice() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getDeviceId() | string |
✅ | ✅ | ✅ | ❌ | ✅ |
| getDeviceType() | string |
✅ | ✅ | ❌ | ❌ | ✅ |
| getDisplay() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getDeviceName() | Promise<string> |
✅ | ✅ | ✅ | ❌ | ✅ |
| getDeviceToken() | Promise<string> |
✅ | ❌ | ❌ | ❌ | ✅ |
| getFirstInstallTime() | Promise<number> |
✅ | ✅ | ✅ | ❌ | ✅ |
| getFingerprint() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getFontScale() | Promise<number> |
✅ | ✅ | ✅ | ❌ | ❌ |
| getFreeDiskStorage() | Promise<number> |
✅ | ✅ | ✅ | ✅ | ✅ |
| getFreeDiskStorageOld() | Promise<number> |
✅ | ✅ | ✅ | ✅ | ✅ |
| getHardware() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getHost() | Promise<string> |
❌ | ✅ | ✅ | ❌ | ❌ |
| getHostNames() | Promise<string[]> |
❌ | ❌ | ✅ | ❌ | ❌ |
| getIpAddress() | Promise<string> |
✅ | ✅ | ✅ | ❌ | ✅ |
| getIncremental() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getInstallerPackageName() | Promise<string> |
✅ | ✅ | ✅ | ❌ | ✅ |
| getInstallReferrer() | Promise<string> |
❌ | ✅ | ✅ | ✅ | ❌ |
| getInstanceId() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getLastUpdateTime() | Promise<number> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getMacAddress() | Promise<string> |
✅ | ✅ | ❌ | ❌ | ✅ |
| getManufacturer() | Promise<string> |
✅ | ✅ | ✅ | ❌ | ✅ |
| getMaxMemory() | Promise<number> |
❌ | ✅ | ✅ | ✅ | ❌ |
| getModel() | string |
✅ | ✅ | ✅ | ❌ | ✅ |
| getPowerState() | Promise<object> |
✅ | ✅ | ✅ | ✅ | ✅ |
| getProduct() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getPreviewSdkInt() | Promise<number> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getReadableVersion() | string |
✅ | ✅ | ✅ | ❌ | ✅ |
| getSerialNumber() | Promise<string> |
❌ | ✅ | ✅ | ❌ | ❌ |
| getSecurityPatch() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getStartupTime() | Promise<number> |
✅ | ✅ | ❌ | ❌ | ✅ |
| getSystemAvailableFeatures() | Promise<string[]> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getSystemName() | string |
✅ | ✅ | ✅ | ❌ | ✅ |
| getSystemVersion() | string |
✅ | ✅ | ✅ | ❌ | ✅ |
| getTags() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getType() | Promise<string> |
❌ | ✅ | ❌ | ❌ | ❌ |
| getTotalDiskCapacity() | Promise<number> |
✅ | ✅ | ✅ | ✅ | ✅ |
| getTotalDiskCapacityOld() | Promise<number> |
✅ | ✅ | ✅ | ✅ | ✅ |
| getTotalMemory() | Promise<number> |
✅ | ✅ | ❌ | ✅ | ✅ |
| getUniqueId() | Promise<string> |
✅ | ✅ | ✅ | ❌ | ✅ |
| getUsedMemory() | Promise<number> |
✅ | ✅ | ✅ | ✅ | ✅ |
| getUserAgent() | Promise<string> |
✅ | ✅ | ❌ | ✅ | ✅ |
| getUserAgentSync() | string |
❌ | ✅ | ❌ | ✅ | ❌ |
| getVersion() | string |
✅ | ✅ | ✅ | ❌ | ✅ |
| getBrightness() | Promise<number> |
✅ | ❌ | ❌ | ❌ | ❌ |
| hasGms() | Promise<boolean> |
❌ | ✅ | ❌ | ❌ | ❌ |
| hasHms() | Promise<boolean> |
❌ | ✅ | ❌ | ❌ | ❌ |
| hasNotch() | boolean |
✅ | ✅ | ✅ | ❌ | ✅ |
| hasDynamicIsland() | boolean |
✅ | ✅ | ✅ | ❌ | ✅ |
| hasSystemFeature() | Promise<boolean> |
❌ | ✅ | ❌ | ❌ | ❌ |
| isAirplaneMode() | Promise<boolean> |
❌ | ✅ |
$ claude mcp add react-native-device-info \
-- python -m otcore.mcp_server <graph>