Device Information for React Native.
Using npm:
npm install --save react-native-device-info
or using yarn:
yarn add react-native-device-info
⚠️ If you are on React Native > 0.47, you must use version 0.11.0 of this library or higher
react-native link react-native-device-info
(or using rnpm
for versions of React Native < 0.27)
rnpm link react-native-device-info
iOS (via Cocoa Pods)
Add the following line to your build targets in your Podfile
pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'
Then run pod install
iOS (without Cocoa Pods)
In XCode, in the project navigator:
- Right click Libraries
- Add Files to [your project's name]
- Go to
node_modules/react-native-device-info
- Add the
.xcodeproj
file
In XCode, in the project navigator, select your project.
- Add the
libRNDeviceInfo.a
from the deviceinfo project to your project's Build Phases âžś Link Binary With Libraries - Click
.xcodeproj
file you added before in the project navigator and go the Build Settings tab. Make sure All is toggled on (instead of Basic). - Look for Header Search Paths and make sure it contains both
$(SRCROOT)/../react-native/React
and$(SRCROOT)/../../React
- Mark both as recursive (should be OK by default).
Run your project (Cmd+R)
(Thanks to @brysgo for writing the instructions)
Android
- in
android/app/build.gradle
:
dependencies {
...
compile "com.facebook.react:react-native:+" // From node_modules
+ compile project(':react-native-device-info')
}
- in
android/settings.gradle
:
...
include ':app'
+ include ':react-native-device-info'
+ project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
- in
MainApplication.java
:
+ import com.learnium.RNDeviceInfo.RNDeviceInfo;
public class MainApplication extends Application implements ReactApplication {
//......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new RNDeviceInfo(),
new MainReactPackage()
);
}
......
}
- in
MainActivity.java
:
+ import com.learnium.RNDeviceInfo.RNDeviceInfo;
public class MainActivity extends ReactActivity {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new RNDeviceInfo(),
new MainReactPackage()
);
}
}
(Thanks to @chirag04 for writing the instructions)
Windows
- Open the solution in Visual Studio for your Windows apps
- right click your in the Explorer and click Add > Existing Project...
- Navigate to
./<app-name>/node_modules/react-native-device-info/windows/RNDeviceInfo
and addRNDeviceInfo.csproj
- this time right click on your React Native Windows app under your solutions directory and click Add > Reference...
- check the
RNDeviceInfo
you just added and press ok - open up
MainPage.cs
for your app and edit the file like so:
+ using RNDeviceInfo;
......
get
{
return new List<IReactPackage>
{
new MainReactPackage(),
+ new RNDeviceInfoPackage(),
};
}
(Thanks to @josephan for writing the instructions)
var DeviceInfo = require('react-native-device-info');
// or import DeviceInfo from 'react-native-device-info';
Method | Return Type | Â iOS | Android | Windows | Since |
---|---|---|---|---|---|
getAPILevel() | number |
❌ | ✅ | ❌ | 0.12.0 |
getApplicationName() | string |
âś… | âś… | âś… | 0.14.0 |
getBrand() | string |
âś… | âś… | âś… | 0.9.3 |
getBuildNumber() | string |
âś… | âś… | âś… | ? |
getBundleId() | string |
âś… | âś… | âś… | ? |
getCarrier() | string |
✅ | ✅ | ❌ | 0.13.0 |
getDeviceCountry() | string |
âś… | âś… | âś… | 0.9.0 |
getDeviceId() | string |
âś… | âś… | âś… | 0.5.0 |
getDeviceLocale() | string |
âś… | âś… | âś… | 0.7.0 |
getDeviceName() | string |
âś… | âś… | âś… | ? |
getFirstInstallTime() | number |
❌ | ✅ | ❌ | 0.12.0 |
getFreeDiskStorage() | number |
✅ | ✅ | ❌ | next |
getIPAddress() | Promise<string> |
❌ | ✅ | ❌ | 0.12.0 |
getInstanceID() | string |
❌ | ✅ | ❌ | ? |
getLastUpdateTime() | number |
❌ | ✅ | ❌ | 0.12.0 |
getMACAddress() | Promise<string> |
❌ | ✅ | ❌ | 0.12.0 |
getManufacturer() | string |
âś… | âś… | âś… | ? |
getMaxMemory() | number |
❌ | ✅ | ❌ | 0.14.0 |
getModel() | string |
âś… | âś… | âś… | ? |
getPhoneNumber() | string |
❌ | ✅ | ❌ | 0.12.0 |
getReadableVersion() | string |
âś… | âś… | âś… | ? |
getSerialNumber() | string |
❌ | ✅ | ❌ | 0.12.0 |
getSystemName() | string |
âś… | âś… | âś… | ? |
getSystemVersion() | string |
âś… | âś… | âś… | ? |
getTimezone() | string |
âś… | âś… | âś… | ? |
getTotalDiskCapacity() | number |
✅ | ✅ | ❌ | next |
getTotalMemory() | number |
✅ | ✅ | ❌ | 0.14.0 |
getUniqueID() | string |
âś… | âś… | âś… | ? |
getUserAgent() | string |
✅ | ✅ | ❌ | 0.7.0 |
getVersion() | string |
âś… | âś… | âś… | ? |
is24Hour() | boolean |
âś… | âś… | âś… | 0.13.0 |
isEmulator() | boolean |
âś… | âś… | âś… | ? |
isPinOrFingerprintSet() | (callback)boolean |
✅ | ✅ | ❌ | 0.10.1 |
isTablet() | boolean |
âś… | âś… | âś… | ? |
Gets the API level.
Examples
const apiLevel = DeviceInfo.getAPILevel();
// iOS: ?
// Android: 25
// Windows: ?
Notes
See API Levels
Gets the application name.
Examples
const appName = DeviceInfo.getApplicationName(); // "Learnium Mobile"
Gets the device brand.
Examples
const brand = DeviceInfo.getBrand();
// iOS: "Apple"
// Android: "Xiaomi"
// Windows: ?
Gets the application build number.
Examples
const buildNumber = DeviceInfo.getBuildNumber();
// iOS: "89"
// Android: 4
// Windows: ?
Notes
There is a type inconsistency: Android return an integer instead of the documented string.
Gets the application bundle identifier.
Examples
const bundleId = DeviceInfo.getBundleId(); // "com.learnium.mobile"
Gets the carrier name (network operator).
Examples
const carrier = DeviceInfo.getCarrier(); // "SOFTBANK"
Gets the device country based on the locale information.
Examples
const deviceCountry = DeviceInfo.getDeviceCountry(); // "US"
Gets the device ID.
Examples
const deviceId = DeviceInfo.getDeviceId();
// iOS: "iPhone7,2"
// Android: "goldfish"
// Windows: ?
Gets the device locale.
Examples
const deviceLocale = DeviceInfo.getDeviceLocale();
// iOS: "en"
// Android: "en-US"
// Windows: ?
Gets the device name.
Examples
const deviceName = DeviceInfo.getDeviceName();
// iOS: "Becca's iPhone 6"
// Android: ?
// Windows: ?
Android Permissions
Gets the time at which the app was first installed, in milliseconds.
Examples
const firstInstallTime = DeviceInfo.getFirstInstallTime();
// Android: 1517681764528
Gets available storage size, in bytes.
Examples
const freeDiskStorage = DeviceInfo.getFreeDiskStorage();
// Android: 17179869184
// iOS: 17179869184
Notes
Android: Returns only available external storage size, not including internal.
Gets the device current IP address.
Examples
DeviceInfo.getIPAddress().then(ip => {
// "92.168.32.44"
});
Android Permissions
Gets the application instance ID.
Examples
const instanceId = DeviceInfo.getInstanceID();
// Android: ?
Notes
Gets the time at which the app was last updated, in milliseconds.
Examples
const lastUpdateTime = DeviceInfo.getLastUpdateTime();
// Android: 1517681764992
Gets the network adapter MAC address.
Examples
DeviceInfo.getMACAddress().then(mac => {
// "E5:12:D8:E5:69:97"
});
Android Permissions
Gets the device manufacturer.
Examples
const manufacturer = DeviceInfo.getManufacturer();
// iOS: "Apple"
// Android: "Google"
// Windows: ?
Returns the maximum amount of memory that the JVM will attempt to use, in bytes.
Examples
const maxMemory = DeviceInfo.getMaxMemory();
// iOS: undefined
// Android: 402653184
// Windows: ?
Gets the device model.
Examples
const model = DeviceInfo.getModel();
// iOS: ?
// Android: ?
// Windows: ?
Gets the device phone number.
Examples
const phoneNumber = DeviceInfo.getPhoneNumber();
// Android: ?
Android Permissions
Gets the application human readable version.
Examples
const readableVersion = DeviceInfo.getReadableVersion();
// iOS: 1.0.1
// Android: 1.0.1
// Windows: ?
Gets the device serial number.
Examples
const serialNumber = DeviceInfo.getSerialNumber();
// iOS: undefined
// Android: ?
// Windows: ?
Gets the device OS name.
Examples
const systemName = DeviceInfo.getSystemName();
// iOS: "iOS"
// Android: "Android"
// Windows: ?
Gets the device OS version.
Examples
const systemVersion = DeviceInfo.getSystemVersion();
// iOS: "11.0"
// Android: "7.1.1"
// Windows: ?
Gets the device default timezone.
Examples
const timezone = DeviceInfo.getTimezone(); // "Africa/Tunis"
Gets full disk storage size, in bytes.
Examples
const storageSize = DeviceInfo.getTotalDiskCapacity();
// Android: 17179869184
// iOS: 17179869184
Gets the device total memory, in bytes.
Examples
const totalMemory = DeviceInfo.getTotalMemory();
// iOS: ?
// Android: 1995018240
// Windows: ?
Gets the device unique ID.
Examples
const uniqueId = DeviceInfo.getUniqueId();
// iOS: "FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9"
// Android: "dd96dec43fb81c97"
// Windows: ?
Notes
This is IDFV on iOS so it will change if all apps from the current apps vendor have been previously uninstalled.
Gets the device User Agent.
Examples
const userAgent = DeviceInfo.getUserAgent();
// 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"
// Android: ?
// Windows: ?
Gets the application version.
Examples
const version = DeviceInfo.getVersion();
// iOS: "1.0"
// Android: "1.0
// Windows: ?
Tells if the user preference is set to 24-hour format.
Examples
const is24Hour = DeviceInfo.is24Hour(); // true
Tells if the application is running in an emulator.
Examples
const isEmulator = DeviceInfo.isEmulator(); // false
Tells if a PIN number or a fingerprint was set for the device.
Examples
DeviceInfo.isPinOrFingerprintSet()(isPinOrFingerprintSet => {
if (!isPinOrFingerprintSet) {
...
}
}
Notes
- Since the device setting for PIN/Fingerprint can be modified while the app is still open, this is available via callback instead of as a constant.
- iOS: Not supported for iOS < 9
Tells if the device is a tablet.
Examples
const isTablet = DeviceInfo.isTablet(); // true
See the CHANGELOG.md.