MCPcopy
hub / github.com/react-native-device-info/react-native-device-info

github.com/react-native-device-info/react-native-device-info @v15.0.2 sqlite

repository ↗ · DeepWiki ↗ · release v15.0.2 ↗
303 symbols 827 edges 38 files 8 documented · 3%
README

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

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

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

Extension points exported contracts — how you extend this code

NativeConstants (Interface)
(no doc)
src/internal/privateTypes.ts
HiddenNativeMethods (Interface)
(no doc)
src/internal/privateTypes.ts
ExposedNativeMethods (Interface)
(no doc)
src/internal/privateTypes.ts
DeviceInfoNativeModule (Interface)
(no doc)
src/internal/privateTypes.ts
DeviceInfoModule (Interface)
(no doc)
src/internal/privateTypes.ts

Core symbols most depended-on inside this repo

getSupportedPlatformInfoFunctions
called by 59
src/internal/supported-platform-info.ts
clearMemo
called by 23
src/internal/supported-platform-info.ts
invoke
called by 21
android/src/main/java/com/learnium/RNDeviceInfo/RNInstallReferrerClient.java
getSupportedPlatformInfoSync
called by 20
src/internal/supported-platform-info.ts
getSupportedPlatformInfoAsync
called by 8
src/internal/supported-platform-info.ts
useOnMount
called by 8
src/internal/asyncHookWrappers.ts
getFreeDiskStorageSync
called by 7
android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
registerReceiver
called by 7
android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java

Shape

Method 177
Function 101
Interface 13
Class 11
Enum 1

Languages

Java62%
TypeScript38%

Modules by API surface

android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java141 symbols
src/index.ts48 symbols
src/web/index.js30 symbols
src/internal/privateTypes.ts9 symbols
android/src/main/java/com/learnium/RNDeviceInfo/resolver/DeviceIdResolver.java8 symbols
example/android/app/src/main/java/com/example/MainApplication.java7 symbols
android/src/main/java/com/learnium/RNDeviceInfo/RNInstallReferrerClient.java7 symbols
jest/react-native-device-info-mock.js6 symbols
example/App.js6 symbols
android/src/main/java/com/learnium/RNDeviceInfo/resolver/DeviceTypeResolver.java6 symbols
src/internal/supported-platform-info.ts5 symbols
example/android/app/src/debug/java/com/example/ReactNativeFlipper.java5 symbols

Dependencies from manifests, versioned

@babel/core7.12.9 · 1×
@babel/runtime7.12.5 · 1×
@jest/globals30.2.0 · 1×
@release-it/conventional-changelog10.0.1 · 1×
@types/jest30.0.0 · 1×
@types/react17.0.39 · 1×
@types/react-native0.67.2 · 1×
appium1.18.3 · 1×
babel-jest26.6.3 · 1×
eslint7 · 1×

For agents

$ claude mcp add react-native-device-info \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact