ProductPromotion
Logo

React.JS

made by https://0x3d.site

GitHub - react-native-device-info/react-native-device-info: Device Information for React Native iOS and Android
Device Information for React Native iOS and Android - react-native-device-info/react-native-device-info
Visit Site

GitHub - react-native-device-info/react-native-device-info: Device Information for React Native iOS and Android

GitHub - react-native-device-info/react-native-device-info: Device Information for React Native iOS and Android

react-native-device-info

npm version npm total downloads npm monthly downloads npm weekly downloads

Device Information for React Native.

TOC

v6 to v7 upgrade

Your iOS Podfile will need to move to an iOS 10 minimum. v7 of this module no longer supports iOS9.

Installation

Using npm:

npm install --save react-native-device-info

or using yarn:

yarn add react-native-device-info

Proguard

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.** {*;}

AndroidX Support

This module defaults to AndroidX you should configure your library versions similar to this in your android/build.gradle file's "ext" block

...
  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"


    //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

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.

Usage

import DeviceInfo from 'react-native-device-info';

// or ES6+ destructured imports

import { getUniqueId, getManufacturer } from 'react-native-device-info';

API

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>
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>
isBatteryCharging() Promise<boolean>
isEmulator() Promise<boolean>
isKeyboardConnected() Promise<bool>
isLandscape() Promise<boolean>
isLocationEnabled() Promise<boolean>
isMouseConnected() Promise<bool>
isHeadphonesConnected() Promise<boolean>
isWiredHeadphonesConnected() Promise<boolean>
isBluetoothHeadphonesConnected() Promise<boolean>
isPinOrFingerprintSet() Promise<boolean>
isTablet() boolean
isLowRamDevice() boolean
isDisplayZoomed() boolean
isTabletMode() Promise<bool>
supported32BitAbis() Promise<string[]>
supported64BitAbis() Promise<string[]>
supportedAbis() Promise<string[]>
syncUniqueId() Promise<string>
getSupportedMediaTypeList() Promise<string[]>

getApiLevel()

Gets the API level.

Examples

DeviceInfo.getApiLevel().then((apiLevel) => {
  // iOS: ?
  // Android: 25
  // Windows: ?
});

Notes

See API Levels


getAndroidId()

Gets the ANDROID_ID. See API documentation for appropriate use.

Examples

DeviceInfo.getAndroidId().then((androidId) => {
  // androidId here
});

getApplicationName()

Gets the application name.

Examples

let appName = DeviceInfo.getApplicationName();
// AwesomeApp

getBaseOs()

The base OS build the product is based on.

Examples

DeviceInfo.getBaseOs().then((baseOs) => {
  // "Windows", "Android" etc
});

getBatteryLevel()

Gets the battery level of the device as a float comprised between 0 and 1.

Examples

DeviceInfo.getBatteryLevel().then((batteryLevel) => {
  // 0.759999
});

Notes

To be able to get actual battery level enable battery monitoring mode for application. Add this code:

[UIDevice currentDevice].batteryMonitoringEnabled = true;

to AppDelegate.m application:didFinishLaunchingWithOptions:

Returns -1 on the iOS Simulator


getBootloader()

The system bootloader version number.

Examples

DeviceInfo.getBootloader().then((bootloader) => {
  // "mw8998-002.0069.00"
});

getBrand()

Gets the device brand.

Examples

let brand = DeviceInfo.getBrand();
// iOS: "Apple"
// Android: "xiaomi"
// Windows: ?

getBuildNumber()

Gets the application build number.

Examples

let buildNumber = DeviceInfo.getBuildNumber();
// iOS: "89"
// Android: "4"
// Windows: ?

getBundleId()

Gets the application bundle identifier.

Examples

let bundleId = DeviceInfo.getBundleId();
// "com.example.AwesomeApp"

isCameraPresent()

Tells if the device has any camera now.

Examples

DeviceInfo.isCameraPresent()
  .then((isCameraPresent) => {
    // true or false
  })
  .catch((cameraAccessException) => {
    // is thrown if a camera device could not be queried or opened by the CameraManager on Android
  });

Notes

  • Hot add/remove of camera is supported.
  • Returns the status of the physical presence of the camera. If camera present but your app don't have permissions to use it, isCameraPresent will still return the true

getCarrier()

Gets the carrier name (network operator).

Examples

DeviceInfo.getCarrier().then((carrier) => {
  // "SOFTBANK"
});

getCodename()

The current development codename, or the string "REL" if this is a release build.

Examples

DeviceInfo.getCodename().then((codename) => {
  // "REL"
});

getDevice()

The name of the industrial design.

Examples

DeviceInfo.getDevice().then((device) => {
  // "walleye"
});

getDeviceId()

Gets the device ID.

Examples

let deviceId = DeviceInfo.getDeviceId();
// iOS: "iPhone7,2"
// Android: "goldfish"
// Windows: "Y3R94UC#AC4"

getDisplay()

A build ID string meant for displaying to the user.

Examples

DeviceInfo.getDisplay().then((display) => {
  // "OPM2.171026.006.G1"
});

getDeviceName()

Gets the device name.

Examples

DeviceInfo.getDeviceName().then((deviceName) => {
  // iOS: "Becca's iPhone 6"
  // Android: ?
  // Windows: ?
});

This used to require the android.permission.BLUETOOTH but the new implementation in v3 does not need it. You may remove that from your AndroidManifest.xml if you had it for this API. iOS 16 and greater require entitlements to access user-defined device name, otherwise a generic value is returned (ie. 'iPad', 'iPhone')


getDeviceToken()

Gets the device token (see DeviceCheck). Only available for iOS 11.0+ on real devices. This will reject the promise when getDeviceToken is not supported, be careful with exception handling.

Examples

DeviceInfo.getDeviceToken().then((deviceToken) => {
  // iOS: "a2Jqsd0kanz..."
});

getFirstInstallTime()

Gets the time at which the app was first installed, in milliseconds.

Examples

DeviceInfo.getFirstInstallTime().then((firstInstallTime) => {
  // Android: 1517681764528
});

getFingerprint()

A string that uniquely identifies this build.

Examples

DeviceInfo.getFingerprint().then((fingerprint) => {
  // "google/walleye/walleye:8.1.0/OPM2.171026.006.G1/4820017:user/release-keys"
});

getFontScale()

Gets the device font scale. The font scale is the ratio of the current system font to the "normal" font size, so if normal text is 10pt and the system font is currently 15pt, the font scale would be 1.5 This can be used to determine if accessability settings has been changed for the device; you may want to re-layout certain views if the font scale is significantly larger ( > 2.0 )

Examples

DeviceInfo.getFontScale().then((fontScale) => {
  // 1.2
});

getFreeDiskStorage()

Method that gets available storage size, in bytes, taking into account both root and data file systems calculation.

On iOS, this method accepts the following optional arguments:

  • 'total': Uses volumeAvailableCapacityKey
  • 'important': Uses volumeAvailableCapacityForImportantUsageKey
  • 'opportunistic': Uses volumeAvailableCapacityForOpportunisticUsageKey

For more details, refer to Apple Documentation on Checking Volume Storage Capacity.

Examples

DeviceInfo.getFreeDiskStorage().then((freeDiskStorage) => {
  // Android: 17179869184
  // iOS: 17179869184
});

DeviceInfo.getFreeDiskStorage('important').then((freeDiskStorage) => {
  // iOS: 18198219342 (important storage)
});

Notes

The API used by this method for Android was changed in v6.0.0. The older version has been maintained below as getFreeDiskStorageOld(). On iOS, getFreeDiskStorage() and getFreeDiskStorageOld() return the same value.


getFreeDiskStorageOld()

Old implementation of method that gets available storage size, in bytes.

Examples

DeviceInfo.getFreeDiskStorageOld().then((freeDiskStorage) => {
  // Android: 17179869184
  // iOS: 17179869184
});

Notes

From developer.android.com:

This method was deprecated in API level 29.

Return the primary shared/external storage directory.

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.


getHardware()

The name of the hardware (from the kernel command line or /proc).

Examples

DeviceInfo.getHardware().then(hardware => {
  // "walleye"
});

getHost()

Hostname

Examples

DeviceInfo.getHost().then((host) => {
  // "wprd10.hot.corp.google.com"
});

getIpAddress()

Deprecated Gets the device current IP address. (of wifi only) Switch to react-native-netinfo/netinfo or react-native-network-info

Examples

DeviceInfo.getIpAddress().then((ip) => {
  // "92.168.32.44"
});

Android Permissions

Notes

Support for iOS was added in 0.22.0


getIncremental()

The internal value used by the underlying source control to represent this build.

Examples

DeviceInfo.getIncremental().then((incremental) => {
  // "4820017"
});

getInstallerPackageName()

The internal value used by the underlying source control to represent this build.

Examples

DeviceInfo.getInstallerPackageName().then((installerPackageName) => {
  // Play Store: "com.android.vending"
  // Amazon: "com.amazon.venezia"
  // Samsung App Store: "com.sec.android.app.samsungapps"
  // iOS: "AppStore", "TestFlight", "Other"
});

getInstallReferrer()

Gets the referrer string upon application installation.

Examples

DeviceInfo.getInstallReferrer().then((installReferrer) => {
  // If the app was installed from https://play.google.com/store/apps/details?id=com.myapp&referrer=my_install_referrer
  // the result will be "my_install_referrer"
});

getInstanceId()

Gets the application instance ID.

This attempts to get an instance ID from these sources, in this order:

  • a value under key instanceId in SharedPreferences file react-native-device-info
  • Firebase IID (if firebaseBomVersion or firebaseIidVersion is defined in gradle ext - deprecated)
  • GMS IID (if googlePlayServicesIidVersion or googlePlayServicesVersion is defined in gradle ext - deprecated)
  • a random UUID generated from java.util.UUID.randomUUID() and stored in SharedPreferences

If you are using the deprecated sources, the instance ID generated is stored in shared preferences so it will be stable during this major version of react-native-device-info.

In a future version of react-native-device-info, the Firebase IID and GMS IID implementations will be removed, and all future values will be the value (if any) stored in SharedPreferences, or a new random UUID that will then be stored and used for that app installation in the future.

Examples

DeviceInfo.getInstanceId().then((instanceId) => {
  // Android: da4e0245-5d6c-402a-a07c-0c5349f229e2
});

Notes

See https://developers.google.com/instance-id/


getLastUpdateTime()

Gets the time at which the app was last updated, in milliseconds.

Examples

DeviceInfo.getLastUpdateTime().then((lastUpdateTime) => {
  // Android: 1517681764992
});

getMacAddress()

Gets the network adapter MAC address.

Examples

DeviceInfo.getMacAddress().then((mac) => {
  // "E5:12:D8:E5:69:97"
});

Android Permissions

Notes

iOS: This method always return "02:00:00:00:00:00" as retrieving the MAC address is disabled since iOS 7


getManufacturer()

Gets the device manufacturer.

Examples

DeviceInfo.getManufacturer().then((manufacturer) => {
  // iOS: "Apple"
  // Android: "Google"
  // Windows: ?
});

getMaxMemory()

Returns the maximum amount of memory that the VM will attempt to use, in bytes.

Examples

DeviceInfo.getMaxMemory().then((maxMemory) => {
  // 402653183
});

getModel()

Gets the device model.

iOS warning: The list with device names is maintained by the community and could lag new devices. It is recommended to use getDeviceId() since it's more reliable and always up-to-date with new iOS devices. We do accept pull requests that add new iOS devices to the list with device names.

Examples

let model = DeviceInfo.getModel();
// iOS: ?
// Android: ?
// Windows: ?

getPhoneNumber()

The getPhoneNumber() has been removed. This method uses deprecated Android APIs. You can use react-native-sim-cards-manager to get the phone number.


getPowerState()

Gets the power state of the device including the battery level, whether it is plugged in, and if the system is currently operating in low power mode. Displays a warning on iOS if battery monitoring not enabled, or if attempted on an emulator (where monitoring is not possible)

Examples

DeviceInfo.getPowerState().then((state) => {
  // {
  //   batteryLevel: 0.759999,
  //   batteryState: 'unplugged',
  //   lowPowerMode: false,
  // }
});

getProduct()

The name of the overall product.

Examples

DeviceInfo.getProduct().then((product) => {
  // "walleye"
});

getPreviewSdkInt()

The developer preview revision of a prerelease SDK.

Examples

DeviceInfo.getPreviewSdkInt().then((previewSdkInt) => {
  // 0
});

getReadableVersion()

Gets the application human readable version (same as getVersion() + '.' + getBuildNumber())

Examples

let readableVersion = DeviceInfo.getReadableVersion();
// iOS: 1.0.1.32
// Android: 1.0.1.234
// Windows: ?

getSerialNumber()

Gets the device serial number. Will be 'unknown' in almost all cases unless you have a privileged app and you know what you're doing.

Examples

DeviceInfo.getSerialNumber().then((serialNumber) => {
  // iOS: unknown
  // Android: ? (maybe a serial number, if your app is privileged)
  // Windows: ? (a serial number, if your app has the "capability smbios")
});

Notes

capability smbios

If you want to use this method in windows, you have to add smbios capability in your aplication. Please following this documentation for add the capability in your manifest file.


getSecurityPatch()

The user-visible security patch level.

Examples

DeviceInfo.getSecurityPatch().then((securityPatch) => {
  // "2018-07-05"
});

getSystemName()

Gets the device OS name.

Examples

let systemName = DeviceInfo.getSystemName();
// iOS: "iOS" on newer iOS devices "iPhone OS" on older devices (including older iPad models), "iPadOS" for iPads using iPadOS 15.0 or higher.
// Android: "Android"
// Windows: ?

getStartupTime()

Gets the time at which the current app process was started, in milliseconds.

Examples

DeviceInfo.getStartupTime().then((startupTime) => {
  // Android: 1517681764528
  // iOS: 1517681764528
});

getSystemVersion()

Gets the device OS version.

Examples

let systemVersion = DeviceInfo.getSystemVersion();
// iOS: "11.0"
// Android: "7.1.1"
// Windows: ?

getBuildId()

Gets build number of the operating system.

Examples

DeviceInfo.getBuildId().then((buildId) => {
  // iOS: "12A269"
  // tvOS: not available
  // Android: "13D15"
  // Windows: not available
});

getTags()

Comma-separated tags describing the build.

Examples

DeviceInfo.getTags().then((tags) => {
  // "release-keys, unsigned, debug",
});

getType()

The type of build.

Examples

DeviceInfo.getType().then((type) => {
  // "user", "eng"
});

getTotalDiskCapacity()

Method that gets full disk storage size, in bytes, taking into account both root and data file systems calculation.

Examples

DeviceInfo.getTotalDiskCapacity().then((capacity) => {
  // Android: 17179869184
  // iOS: 17179869184
});

Notes

The API used by this method for Android was changed in v6.0.0. The older version has been maintained below as getTotalDiskCapacityOld(). On iOS, getTotalDiskCapacity() and getTotalDiskCapacityOld() return the same value.


getTotalDiskCapacityOld()

Old implementation of method that gets full disk storage size, in bytes.

Examples

DeviceInfo.getTotalDiskCapacityOld().then((capacity) => {
  // Android: 17179869184
  // iOS: 17179869184
});

getTotalMemory()

Gets the device total memory, in bytes.

Examples

DeviceInfo.getTotalMemory().then((totalMemory) => {
  // 1995018240
});

getUniqueId()

This identifier is considered sensitive information in some app stores (e.g. Huawei or Google Play) and may lead to your app being removed or rejected, if used without user consent or for unapproved purposes. Refer to store policies for more information (see notes below).

Gets the device unique ID. On Android it is currently identical to getAndroidId() in this module. On iOS it uses the DeviceUID uid identifier. On Windows it uses Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation.id.

Examples

DeviceInfo.getUniqueId().then((uniqueId) => {
// iOS: "FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9"
// Android: "dd96dec43fb81c97"
// Windows: "{2cf7cb3c-da7a-d508-0d7f-696bb51185b4}"
});

Notes

  • iOS: This is IDFV or a random string if IDFV is unavaliable. Once UID is generated it is stored in iOS Keychain and NSUserDefaults. So it would stay the same even if you delete the app or reset IDFV. You can carefully consider it a persistent unique ID. It can be changed only in case someone manually override values in Keychain/NSUserDefaults or if Apple would change Keychain and NSUserDefaults implementations. Beware: The IDFV is calculated using your bundle identifier and thus will be different in app extensions.
  • android: Prior to Oreo, this id (ANDROID_ID) will always be the same once you set up your phone.
  • android: Google Play policy, see "persistent device identifiers". Huawei - AppGallery Review Guidelines see "permanent device identifier" and "obtaining user consent".

syncUniqueId()

This method is intended for iOS.

This synchronizes uniqueId with IDFV or sets new a random string.

On iOS it uses the DeviceUID uid identifier. On other platforms it just call getUniqueId() in this module.

Examples

DeviceInfo.syncUniqueId().then((uniqueId) => {
  // iOS: "FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9"
  // Android: "dd96dec43fb81c97"
  // Windows: ?
});

Notes

  • If user moved or restored data from one iOS device to second iOS device then he will have two different devices with same uniqueId in Keychain/NSUserDefaults. User can call syncUniqueId() on new iOS device. That will update his uniqueId from IDFV or a random string.

getUsedMemory()

Gets the app memory usage, in bytes.

⚠️ A note from the Android docs.

Note: this method is only intended for debugging or building a user-facing process management UI.

Examples

DeviceInfo.getUsedMemory().then((usedMemory) => {
  // 23452345
});

getSupportedMediaTypeList()

This method gets the list of supported media codecs.

Examples

DeviceInfo.getSupportedMediaTypeList().then((string[]) => {
  // ["audio/mpeg", "audio/mp4a-latm", "audio/mp4a-latm", "audio/mp4a-latm", "audio/mp4a-latm", "video/avc", "video/3gpp", "video/hevc", "video/mp4v-es", "video/av01", "video/avc", "video/avc", "video/avc", "video/avc"]
});

getUserAgent()

Gets the device User Agent.

Examples

DeviceInfo.getUserAgent().then((userAgent) => {
  // iOS: "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143"
  // tvOS: not available
  // Android: "Mozilla/5.0 (Linux; Android 12; sdk_gphone64_arm64 Build/SE1A.220630.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/91.0.4472.114 Mobile Safari/537.36"
  // Windows: ?
});

getVersion()

Gets the application version. Take into account that a version string is device/OS formatted and can contain any additional data (such as build number etc.). If you want to be sure about version format, you can use a regular expression to get the desired portion of the returned version string.

Examples

let version = DeviceInfo.getVersion();
// iOS: "1.0"
// Android: "1.0" or "1.0.2-alpha.12"
// Windows: ?

isAirplaneMode()

Tells if the device is in Airplane Mode.

Examples

DeviceInfo.isAirplaneMode().then((airplaneModeOn) => {
  // false
});

Notes

  • This only works if the remote debugger is disabled.

isBatteryCharging()

Tells if the battery is currently charging.

Examples

DeviceInfo.isBatteryCharging().then((isCharging) => {
  // true or false
});

isEmulator()

Tells if the application is running in an emulator.

Examples

DeviceInfo.isEmulator().then((isEmulator) => {
  // false
});

isKeyboardConnected()

Tells if the device has a keyboard connected.

Examples

let isKeyboardConnected = DeviceInfo.isKeyboardConnected();
// true

isPinOrFingerprintSet()

Tells if a PIN number or a fingerprint was set for the device.

Examples

DeviceInfo.isPinOrFingerprintSet().then((isPinOrFingerprintSet) => {
  if (!isPinOrFingerprintSet) {
    // ...
  }
});

isTablet()

Tells if the device is a tablet.

Examples

let isTablet = DeviceInfo.isTablet();
// true

isLowRamDevice()

Tells if the device has low RAM.

Examples

let isLowRamDevice = DeviceInfo.isLowRamDevice();
// true

isDisplayZoomed()

Tells if the user changed Display Zoom to Zoomed

Examples

let isDisplayZoomed = DeviceInfo.isDisplayZoomed();
// true

isTabletMode()

Tells if the device is in tablet mode.

Examples

let isTabletMode = DeviceInfo.isTabletMode();
// true

isLandscape()

Tells if the device is currently in landscape mode.

Examples

DeviceInfo.isLandscape().then((isLandscape) => {
  // true
});

isMouseConnected()

Tells if the device has a mouse connected.

Examples

let isMouseConnected = DeviceInfo.isMouseConnected();
// true

hasGms()

Tells if the device supports Google Mobile Services.

Examples

DeviceInfo.hasGms().then((hasGms) => {
  // true
});

hasHms()

Tells if the device supports Huawei Mobile Services.

Examples

DeviceInfo.hasHms().then((hasHms) => {
  // true
});

hasNotch()

Tells if the device has a notch.

Examples

let hasNotch = DeviceInfo.hasNotch();
// true

hasDynamicIsland()

Tells if the device has a dynamic island.

Examples

let hasDynamicIsland = DeviceInfo.hasDynamicIsland();
// true

getDeviceType()

Returns the device's type as a string, which will be one of:

  • Handset
  • Tablet
  • Tv
  • Desktop
  • GamingConsole
  • Headset
  • unknown

Examples

let type = DeviceInfo.getDeviceType();
// 'Handset'

supported32BitAbis()

An ordered list of 32 bit ABIs supported by this device.

Examples

DeviceInfo.supported32BitAbis().then((abis) => {
  // ["armeabi-v7a", "armeabi"]
});

supported64BitAbis()

An ordered list of 64 bit ABIs supported by this device.

Examples

DeviceInfo.supported64BitAbis().then((abis) => {
  // ["arm64-v8a"]
});

supportedAbis()

Returns a list of supported processor architecture version

Examples

DeviceInfo.supportedAbis().then((abis) => {
  // [ "arm64 v8", "Intel x86-64h Haswell", "arm64-v8a", "armeabi-v7a", "armeabi", "win_x86", "win_arm", "win_x64" ]
});

hasSystemFeature(feature)

Tells if the device has a specific system feature.

Examples

DeviceInfo.hasSystemFeature('amazon.hardware.fire_tv').then((hasFeature) => {
  // true or false
});

getSystemAvailableFeatures()

Returns a list of available system features on Android.

Examples

DeviceInfo.getSystemAvailableFeatures().then((features) => {
  // ["android.software.backup", "android.hardware.screen.landscape", "android.hardware.wifi", ...]
});

isLocationEnabled()

Tells if the device has location services turned off at the device-level (NOT related to app-specific permissions)

Examples

DeviceInfo.isLocationEnabled().then((enabled) => {
  // true or false
});

isHeadphonesConnected()

Tells if the device is connected to wired headset or bluetooth headphones

Examples

DeviceInfo.isHeadphonesConnected().then((enabled) => {
  // true or false
});

isWiredHeadphonesConnected()

Tells if the device is connected to wired headset

Examples

DeviceInfo.isWiredHeadphonesConnected().then((enabled) => {
  // true or false
});

isBluetoothHeadphonesConnected()

Tells if the device is connected to bluetooth headset

Examples

DeviceInfo.isBluetoothHeadphonesConnected().then((enabled) => {
  // true or false
});

getAvailableLocationProviders()

Returns an object of platform-specfic location providers/servcies, with boolean value whether or not they are currently available.

NOTE: This function requires access to the Location permission on Android

Android Example

DeviceInfo.getAvailableLocationProviders().then((providers) => {
  // {
  //   gps: true
  //   network: true
  //   passive: true
  // }
});

iOS Example

DeviceInfo.getAvailableLocationProviders().then((providers) => {
  // {
  //   headingAvailable: false
  //   isRangingAvailable: false
  //   locationServicesEnabled: true
  //   significantLocationChangeMonitoringAvailable: true
  // }
});

getBrightness()

Gets the current brightness level of the device's main screen. Currently iOS only. Returns a number between 0.0 and 1.0, inclusive.

Examples

DeviceInfo.getBrightness().then((brightness) => {
  // iOS: 0.6
});

Hooks & Events

Supported in Windows, iOS & Android (web support for battery/charging-related APIs).

useBatteryLevel or RNDeviceInfo_batteryLevelDidChange

Fired when the battery level changes; sent no more frequently than once per minute.

Examples

import { useBatteryLevel } from 'react-native-device-info';

const batteryLevel = useBatteryLevel(); // 0.759999

<Text>{batteryLevel}</Text>;
import { NativeEventEmitter, NativeModules } from 'react-native';
const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo);

deviceInfoEmitter.addListener('RNDeviceInfo_batteryLevelDidChange', (level) => {
  // 0.759999
});

useBatteryLevelIsLow or RNDeviceInfo_batteryLevelIsLow

Fired when the battery level is considered low (multiple times untill charged)

Platform Percentage
iOS 20
Android 15
Web 20
Windows 20

Examples

import { useBatteryLevelIsLow } from 'react-native-device-info';

const batteryLevelIsLow = useBatteryLevelIsLow(); // 0.19

<Text>{batteryLevelIsLow}</Text>;
import { NativeEventEmitter, NativeModules } from 'react-native';
const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo);

deviceInfoEmitter.addListener('RNDeviceInfo_batteryLevelIsLow', (level) => {
  // 0.19
});

usePowerState or RNDeviceInfo_powerStateDidChange

Fired when the battery state changes or device enters in the power saving mode, for example when the device enters charging mode or is unplugged.

Examples

import { usePowerState } from 'react-native-device-info';

const powerState = usePowerState();
  // {
  //   batteryLevel: 0.759999,
  //   batteryState: 'unplugged',
  //   lowPowerMode: false,
  // }

<Text>{powerState}</Text>;
import { NativeEventEmitter, NativeModules } from 'react-native'
const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo)

deviceInfoEmitter.addListener('RNDeviceInfo_powerStateDidChange', { powerState } => {
  // {
  //   batteryLevel: 0.759999,
  //   batteryState: 'unplugged',
  //   lowPowerMode: false,
  // }
});

useFirstInstallTime

Gets the time at which the app was first installed, in milliseconds.

Example

import { useFirstInstallTime } from 'react-native-device-info';

const { loading, result } = useFirstInstallTime(); // { loading: true, result: 1517681764528}

<Text>{loading ? 'loading...' : result}</Text>;

useDeviceName

Gets the device name.

Example

import { useDeviceName } from 'react-native-device-info';

const { loading, result } = useDeviceName(); // { loading: true, result: "Becca's iPhone 6"}

<Text>{loading ? 'loading...' : result}</Text>;

useHasSystemFeature

Tells if the device has a specific system feature.

Example

import { useHasSystemFeature } from 'react-native-device-info';

const { loading, result } = useHasSystemFeature('amazon.hardware.fire_tv'); // { loading: true, result: false }

<Text>{loading ? 'loading...' : result}</Text>;

useIsEmulator

Get whether the application is running in an emulator.

Example

import { useIsEmulator } from 'react-native-device-info';

const { loading, result } = useIsEmulator(); // { loading: true, result: false }

<Text>{loading ? 'loading...' : result}</Text>;

useManufacturer

Gets the device manufacturer.

Example

import { useManufacturer } from 'react-native-device-info';

const { loading, result } = useManufacturer(); // { loading: true, result: "Apple"}

<Text>{loading ? 'loading...' : result}</Text>;

useIsHeadphonesConnected

Tells if the device is connected to wired headset or bluetooth headphones.

This hook subscribes to the event, RNDeviceInfo_headphoneConnectionDidChange , and updates the result field accordingly.

Example

import { useIsHeadphonesConnected } from 'react-native-device-info';

const { loading, result } = useIsHeadphonesConnected(); // { loading: true, result: false}

<Text>{loading ? 'loading...' : result}</Text>;

useIsWiredHeadphonesConnected

Tells if the device is connected to wired headset.

This hook subscribes to the event, RNDeviceInfo_headphoneWiredConnectionDidChange , and updates the result field accordingly.

Example

import { useIsWiredHeadphonesConnected } from 'react-native-device-info';

const { loading, result } = useIsWiredHeadphonesConnected(); // { loading: true, result: false}

<Text>{loading ? 'loading...' : result}</Text>;

useIsBluetoothHeadphonesConnected

Tells if the device is connected to bluetooth headphones.

This hook subscribes to the event, RNDeviceInfo_headphoneBluetoothConnectionDidChange , and updates the result field accordingly.

Example

import { useIsBluetoothHeadphonesConnected } from 'react-native-device-info';

const { loading, result } = useIsBluetoothHeadphonesConnected(); // { loading: true, result: false}

<Text>{loading ? 'loading...' : result}</Text>;

useBrightness

Gets the current brightness level of the device's main screen. Currently iOS only. Returns a number between 0.0 and 1.0, inclusive.

This hook subscribes to the event, RNDeviceInfo_brightnessDidChange , and updates the brightness field accordingly.

Example

import { useBrightness } from 'react-native-device-info';

const brightness = useBrightness(); // 0.46578987897654567

<Text>{brightness}</Text>;
import { NativeEventEmitter, NativeModules } from 'react-native';

const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo);

deviceInfoEmitter.addListener('RNDeviceInfo_brightnessDidChange', (brightness) => {
  // 0.46578987897654567
});

=======

Native interoperatibily

If you need to check for device type from the native side, you can use the following:

import com.learnium.resolver.DeviceTypeResolver

...
deviceTypeResolver = new DeviceTypeResolver(context);
...
//Check if the device is a Tablet:
if(deviceTypeResolver.isTablet){
  ...
}else{
  ...
}

Troubleshooting

When installing or using react-native-device-info, you may encounter the following problems:

react-native-device-info uses com.google.android.gms:play-services-gcm to provide getInstanceId(). This can lead to conflicts when building the Android application.

If you're using a different version of com.google.android.gms:play-services-gcm in your app, you can define the googlePlayServicesVersion gradle variable in your build.gradle file to tell react-native-device-info what version it should require. See the example project included here for a sample.

If you're using a different library that conflicts with com.google.android.gms:play-services-gcm, and you are certain you know what you are doing such that you will avoid version conflicts, you can simply ignore this dependency in your gradle file:

 compile(project(':react-native-device-info')) {
    exclude group: 'com.google.android.gms'
}

Seems to be a bug caused by react-native link. You can manually delete libRNDeviceInfo-tvOS.a in Xcode -> [Your iOS build target] -> Build Phrases -> Link Binary with Libraries.

This is a system level log that may be turned off by executing: xcrun simctl spawn booted log config --mode "level:off" --subsystem com.apple.CoreTelephony. To undo the command, you can execute: xcrun simctl spawn booted log config --mode "level:info" --subsystem com.apple.CoreTelephony

RN<=59 You may need to adjust your Podfile like this if you use Cocoapods and have undefined symbols or duplicate React definitions

target 'yourTargetName' do
  # See http://facebook.github.io/react-native/docs/integration-with-existing-apps.html#configuring-cocoapods-dependencies
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge', # Include this for RN >= 0.47
    'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
    'RCTText',
    'RCTNetwork',
    'RCTWebSocket', # Needed for debugging
    'RCTAnimation', # Needed for FlatList and animations running on native UI thread
    # Add any other subspecs you want to use in your project
  ]

  # Explicitly include Yoga if you are using RN >= 0.42.0
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  # Third party deps podspec link - you may have multiple pods here, just an example
  pod 'RNDeviceInfo', path: '../node_modules/react-native-device-info'

end

# if you see errors about React duplicate definitions, this fixes it. The same works for yoga.
post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == "React"
      target.remove_from_project
    end
  end
end

react-native-device-info contains native code, and needs to be mocked. Jest Snapshot support may work though.

If you do not have a Jest Setup file configured, you should add the following to your Jest settings and create the jest.setup.js file in project root:

setupFiles: ['<rootDir>/jest.setup.js'];

You should then add the following to your Jest setup file to mock the DeviceInfo Native Module:

import mockRNDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock';

jest.mock('react-native-device-info', () => mockRNDeviceInfo);

Checkout the example project for more information.

Some of the APIs (like getBatteryState) will throw warnings in certain conditions like on tvOS or the iOS emulator. This won't be visible in production but even in development it may be irritating. It is useful to have the warnings because these devices return no state, and that can be surprising, leading to github support issues. The warnings is intended to educate you as a developer. If the warnings are troublesome you may try this in your code to suppress them:

import { LogBox } from 'react-native';
LogBox.ignoreLogs(['Battery state']);

Release Notes

See the CHANGELOG.md.

Contributing

Please see the contributing guide.

react-native-dom

As a courtesy to developers, this library was made compatible in v0.21.6 with react-native-dom and react-native-web by providing an empty polyfill in order to avoid breaking builds.

Only getUserAgent() will return a correct value. All other API methods will return an "empty" value of its documented return type: 0 for numbers, '' for strings, false for booleans.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory