UNPKG

55.9 kBMarkdownView Raw
1<!-- markdownlint-disable MD024 MD034 MD033 -->
2
3# react-native-device-info
4
5[![npm version](https://badge.fury.io/js/react-native-device-info.svg)](http://badge.fury.io/js/react-native-device-info)
6[![npm total downloads](https://img.shields.io/npm/dt/react-native-device-info.svg)](https://img.shields.io/npm/dt/react-native-device-info.svg)
7[![npm monthly downloads](https://img.shields.io/npm/dm/react-native-device-info.svg)](https://img.shields.io/npm/dm/react-native-device-info.svg)
8[![npm weekly downloads](https://img.shields.io/npm/dw/react-native-device-info.svg)](https://img.shields.io/npm/dw/react-native-device-info.svg)
9
10Device Information for [React Native](https://github.com/facebook/react-native).
11
12## TOC
13
14- [Installation](#installation)
15- [Linking](#linking)
16- [Usage](#usage)
17- [API](#api)
18- [Hooks & Events](#hooks--events)
19- [Troubleshooting](#troubleshooting)
20- [Release Notes](#release-notes)
21- [react-native-dom / react-native-web](#react-native-dom)
22
23## v6 to v7 upgrade
24
25Your iOS Podfile will need to move to an iOS 10 minimum. v7 of this module no longer supports iOS9.
26
27## Installation
28
29Using npm:
30
31```shell
32npm install --save react-native-device-info
33```
34
35or using yarn:
36
37```shell
38yarn add react-native-device-info
39```
40
41## Proguard
42
43If you want to use Install Referrer tracking, you will need to add this config to your Proguard config
44
45```
46-keep class com.android.installreferrer.api.** {
47 *;
48}
49```
50
51If you are experiencing issues with hasGms() on your release apks, please add the following rule to your Proguard config
52
53```
54-keep class com.google.android.gms.common.** {*;}
55```
56
57## AndroidX Support
58
59This module defaults to AndroidX you should configure your library versions similar to this in your `android/build.gradle` file's "ext" block
60
61<details>
62 <summary>Android</summary>
63
64```gradle
65...
66 ext {
67 // dependency versions
68
69 We have 3 options for deviceId:
70 //Option 1 (latest):
71 firebaseIidVersion = "19.0.1" // default: "19.0.1"
72 //Option 2 (legacy GooglePlay dependency but using AndroidX):
73 googlePlayServicesIidVersion = "17.0.0" // default: "17.0.0" - AndroidX
74 //Option 3 (legacy GooglePlay dependency before AndroidX):
75 googlePlayServicesIidVersion = "16.0.1"
76
77
78 //include as needed:
79 compileSdkVersion = "28" // default: 28 (28 is required for AndroidX)
80 targetSdkVersion = "28" // default: 28 (28 is required for AndroidX)
81 supportLibVersion = '1.0.2' // Use '28.0.0' or don't specify for old libraries, '1.0.2' or similar for AndroidX
82 mediaCompatVersion = '1.0.1' // Do not specify if using old libraries, specify '1.0.1' or similar for androidx.media:media dependency
83 supportV4Version = '1.0.0' // Do not specify if using old libraries, specify '1.0.0' or similar for androidx.legacy:legacy-support-v4 dependency
84 }
85...
86```
87
88</details>
89
90If you need non-AndroidX you will need to use the jetifier package in reverse mode, documentation available with that package.
91
92## Linking
93
94Linking 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.
95
96Automatic linking is supported for all platforms (even windows on React native >= 0.63!)
97
98Previous 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._
99
100## Usage
101
102```js
103import DeviceInfo from 'react-native-device-info';
104
105// or ES6+ destructured imports
106
107import { getUniqueId, getManufacturer } from 'react-native-device-info';
108```
109
110## API
111
112Note 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).
113
114Most 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.
115
116**Note about getUserAgentSync**
117
118While the asynchronous method `getUserAgent` is available on both platforms, `getUserAgentSync` is only supported on Android.
119
120The 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.
121
122| Method | Return Type | iOS | Android | Windows | Web | visionOS |
123| ------------------------------------------------------------------- | ------------------- | :--: | :-----: | :-----: | :-: | :------: |
124| [getAndroidId()](#getandroidid) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
125| [getApiLevel()](#getapilevel) | `Promise<number>` | ❌ | ✅ | ❌ | ❌ | ❌ |
126| [getApplicationName()](#getapplicationname) | `string` | ✅ | ✅ | ✅ | ❌ | ✅ |
127| [getAvailableLocationProviders()](#getAvailableLocationProviders) | `Promise<Object>` | ✅ | ✅ | ❌ | ❌ | ✅ |
128| [getBaseOs()](#getbaseOs) | `Promise<string>` | ❌ | ✅ | ✅ | ✅ | ❌ |
129| [getBuildId()](#getbuildid) | `Promise<string>` | ✅ | ✅ | ✅ | ❌ | ✅ |
130| [getBatteryLevel()](#getbatterylevel) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ | ✅ |
131| [getBootloader()](#getbootloader) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
132| [getBrand()](#getbrand) | `string` | ✅ | ✅ | ✅ | ❌ | ✅ |
133| [getBuildNumber()](#getbuildnumber) | `string` | ✅ | ✅ | ✅ | ❌ | ✅ |
134| [getBundleId()](#getbundleid) | `string` | ✅ | ✅ | ✅ | ❌ | ✅ |
135| [isCameraPresent()](#iscamerapresent) | `Promise<boolean>` | ❌ | ✅ | ✅ | ✅ | ❌ |
136| [getCarrier()](#getcarrier) | `Promise<string>` | ✅ | ✅ | ❌ | ❌ | ❌ |
137| [getCodename()](#getcodename) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
138| [getDevice()](#getdevice) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
139| [getDeviceId()](#getdeviceid) | `string` | ✅ | ✅ | ✅ | ❌ | ✅ |
140| [getDeviceType()](#getDeviceType) | `string` | ✅ | ✅ | ❌ | ❌ | ✅ |
141| [getDisplay()](#getdisplay) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
142| [getDeviceName()](#getdevicename) | `Promise<string>` | ✅ | ✅ | ✅ | ❌ | ✅ |
143| [getDeviceToken()](#getdevicetoken) | `Promise<string>` | ✅ | ❌ | ❌ | ❌ | ✅ |
144| [getFirstInstallTime()](#getfirstinstalltime) | `Promise<number>` | ✅ | ✅ | ✅ | ❌ | ✅ |
145| [getFingerprint()](#getfingerprint) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
146| [getFontScale()](#getfontscale) | `Promise<number>` | ✅ | ✅ | ✅ | ❌ | ❌ |
147| [getFreeDiskStorage()](#getfreediskstorage) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ | ✅ |
148| [getFreeDiskStorageOld()](#getfreediskstorageold) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ | ✅ |
149| [getHardware()](#gethardware) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
150| [getHost()](#gethost) | `Promise<string>` | ❌ | ✅ | ✅ | ❌ | ❌ |
151| [getHostNames()](#getHostNames) | `Promise<string[]>` | ❌ | ❌ | ✅ | ❌ | ❌ |
152| [getIpAddress()](#getipaddress) | `Promise<string>` | ✅ | ✅ | ✅ | ❌ | ✅ |
153| [getIncremental()](#getincremental) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
154| [getInstallerPackageName()](#getinstallerpackagename) | `Promise<string>` | ✅ | ✅ | ✅ | ❌ | ✅ |
155| [getInstallReferrer()](#getinstallreferrer) | `Promise<string>` | ❌ | ✅ | ✅ | ✅ | ❌ |
156| [getInstanceId()](#getinstanceid) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
157| [getLastUpdateTime()](#getlastupdatetime) | `Promise<number>` | ❌ | ✅ | ❌ | ❌ | ❌ |
158| [getMacAddress()](#getmacaddress) | `Promise<string>` | ✅ | ✅ | ❌ | ❌ | ✅ |
159| [getManufacturer()](#getmanufacturer) | `Promise<string>` | ✅ | ✅ | ✅ | ❌ | ✅ |
160| [getMaxMemory()](#getmaxmemory) | `Promise<number>` | ❌ | ✅ | ✅ | ✅ | ❌ |
161| [getModel()](#getmodel) | `string` | ✅ | ✅ | ✅ | ❌ | ✅ |
162| [getPowerState()](#getpowerstate) | `Promise<object>` | ✅ | ✅ | ✅ | ✅ | ✅ |
163| [getProduct()](#getproduct) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
164| [getPreviewSdkInt()](#getPreviewSdkInt) | `Promise<number>` | ❌ | ✅ | ❌ | ❌ | ❌ |
165| [getReadableVersion()](#getreadableversion) | `string` | ✅ | ✅ | ✅ | ❌ | ✅ |
166| [getSerialNumber()](#getserialnumber) | `Promise<string>` | ❌ | ✅ | ✅ | ❌ | ❌ |
167| [getSecurityPatch()](#getsecuritypatch) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
168| [getStartupTime()](#getstartuptime) | `Promise<number>` | ✅ | ✅ | ❌ | ❌ | ✅ |
169| [getSystemAvailableFeatures()](#getSystemAvailableFeatures) | `Promise<string[]>` | ❌ | ✅ | ❌ | ❌ | ❌ |
170| [getSystemName()](#getsystemname) | `string` | ✅ | ✅ | ✅ | ❌ | ✅ |
171| [getSystemVersion()](#getsystemversion) | `string` | ✅ | ✅ | ✅ | ❌ | ✅ |
172| [getTags()](#gettags) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
173| [getType()](#gettype) | `Promise<string>` | ❌ | ✅ | ❌ | ❌ | ❌ |
174| [getTotalDiskCapacity()](#gettotaldiskcapacity) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ | ✅ |
175| [getTotalDiskCapacityOld()](#gettotaldiskcapacityold) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ | ✅ |
176| [getTotalMemory()](#gettotalmemory) | `Promise<number>` | ✅ | ✅ | ❌ | ✅ | ✅ |
177| [getUniqueId()](#getuniqueid) | `Promise<string>` | ✅ | ✅ | ✅ | ❌ | ✅ |
178| [getUsedMemory()](#getusedmemory) | `Promise<number>` | ✅ | ✅ | ✅ | ✅ | ✅ |
179| [getUserAgent()](#getuseragent) | `Promise<string>` | ✅ | ✅ | ❌ | ✅ | ✅ |
180| [getUserAgentSync()](#getuseragent) | `string` | ❌ | ✅ | ❌ | ✅ | ❌ |
181| [getVersion()](#getversion) | `string` | ✅ | ✅ | ✅ | ❌ | ✅ |
182| [getBrightness()](#getBrightness) | `Promise<number>` | ✅ | ❌ | ❌ | ❌ | ❌ |
183| [hasGms()](#hasGms) | `Promise<boolean>` | ❌ | ✅ | ❌ | ❌ | ❌ |
184| [hasHms()](#hasHms) | `Promise<boolean>` | ❌ | ✅ | ❌ | ❌ | ❌ |
185| [hasNotch()](#hasNotch) | `boolean` | ✅ | ✅ | ✅ | ❌ | ✅ |
186| [hasDynamicIsland()](#hasDynamicIsland) | `boolean` | ✅ | ✅ | ✅ | ❌ | ✅ |
187| [hasSystemFeature()](#hassystemfeaturefeature) | `Promise<boolean>` | ❌ | ✅ | ❌ | ❌ | ❌ |
188| [isAirplaneMode()](#isairplanemode) | `Promise<boolean>` | ❌ | ✅ | ❌ | ✅ | ❌ |
189| [isBatteryCharging()](#isbatterycharging) | `Promise<boolean>` | ✅ | ✅ | ✅ | ✅ | ✅ |
190| [isEmulator()](#isemulator) | `Promise<boolean>` | ✅ | ✅ | ✅ | ❌ | ✅ |
191| [isKeyboardConnected()](#iskeyboardconnected) | `Promise<bool>` | ❌ | ❌ | ✅ | ❌ | ❌ |
192| [isLandscape()](#isLandscape) | `Promise<boolean>` | ✅ | ✅ | ✅ | ❌ | ✅ |
193| [isLocationEnabled()](#isLocationEnabled) | `Promise<boolean>` | ✅ | ✅ | ❌ | ✅ | ✅ |
194| [isMouseConnected()](#ismouseconneted) | `Promise<bool>` | ❌ | ❌ | ✅ | ❌ | ❌ |
195| [isHeadphonesConnected()](#isHeadphonesConnected) | `Promise<boolean>` | ✅ | ✅ | ❌ | ❌ | ✅ |
196| [isWiredHeadphonesConnected()](#isWiredHeadphonesConnected) | `Promise<boolean>` | ✅ | ✅ | ❌ | ❌ | ✅ |
197| [isBluetoothHeadphonesConnected()](#isBluetoothHeadphonesConnected) | `Promise<boolean>` | ✅ | ✅ | ❌ | ❌ | ✅ |
198| [isPinOrFingerprintSet()](#ispinorfingerprintset) | `Promise<boolean>` | ✅ | ✅ | ✅ | ❌ | ✅ |
199| [isTablet()](#istablet) | `boolean` | ✅ | ✅ | ✅ | ❌ | ✅ |
200| [isLowRamDevice()](#istablet) | `boolean` | ❌ | ✅ | ❌ | ❌ | ❌ |
201| [isDisplayZoomed()](#isdisplayzoomed) | `boolean` | ✅ | ❌ | ❌ | ❌ | ❌ |
202| [isTabletMode()](#istabletmode) | `Promise<bool>` | ❌ | ❌ | ✅ | ❌ | ❌ |
203| [supported32BitAbis()](#supported32BitAbis) | `Promise<string[]>` | ❌ | ✅ | ❌ | ❌ | ❌ |
204| [supported64BitAbis()](#supported64BitAbis) | `Promise<string[]>` | ❌ | ✅ | ❌ | ❌ | ❌ |
205| [supportedAbis()](#supportedAbis) | `Promise<string[]>` | ✅ | ✅ | ✅ | ❌ | ✅ |
206| [syncUniqueId()](#syncuniqueid) | `Promise<string>` | ✅ | ❌ | ❌ | ❌ | ✅ |
207| [getSupportedMediaTypeList()](#getSupportedMediaTypeList) | `Promise<string[]>` | ❌ | ✅ | ❌ | ❌ | ❌ |
208
209---
210
211### getApiLevel()
212
213Gets the API level.
214
215#### Examples
216
217```js
218DeviceInfo.getApiLevel().then((apiLevel) => {
219 // iOS: ?
220 // Android: 25
221 // Windows: ?
222});
223```
224
225#### Notes
226
227> See [API Levels](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)
228
229---
230
231### getAndroidId()
232
233Gets the ANDROID_ID. See [API documentation](https://developer.android.com/reference/android/provider/Settings.Secure#ANDROID_ID) for appropriate use.
234
235#### Examples
236
237```js
238DeviceInfo.getAndroidId().then((androidId) => {
239 // androidId here
240});
241```
242
243---
244
245### getApplicationName()
246
247Gets the application name.
248
249#### Examples
250
251```js
252let appName = DeviceInfo.getApplicationName();
253// AwesomeApp
254```
255
256---
257
258### getBaseOs()
259
260The base OS build the product is based on.
261
262#### Examples
263
264```js
265DeviceInfo.getBaseOs().then((baseOs) => {
266 // "Windows", "Android" etc
267});
268```
269
270---
271
272### getBatteryLevel()
273
274Gets the battery level of the device as a float comprised between 0 and 1.
275
276#### Examples
277
278```js
279DeviceInfo.getBatteryLevel().then((batteryLevel) => {
280 // 0.759999
281});
282```
283
284#### Notes
285
286> To be able to get actual battery level enable battery monitoring mode for application.
287> Add this code:
288
289```objective-c
290[UIDevice currentDevice].batteryMonitoringEnabled = true;
291```
292
293> to AppDelegate.m application:didFinishLaunchingWithOptions:
294>
295> Returns -1 on the iOS Simulator
296
297---
298
299### getBootloader()
300
301The system bootloader version number.
302
303#### Examples
304
305```js
306DeviceInfo.getBootloader().then((bootloader) => {
307 // "mw8998-002.0069.00"
308});
309```
310
311---
312
313### getBrand()
314
315Gets the device brand.
316
317#### Examples
318
319```js
320let brand = DeviceInfo.getBrand();
321// iOS: "Apple"
322// Android: "xiaomi"
323// Windows: ?
324```
325
326---
327
328### getBuildNumber()
329
330Gets the application build number.
331
332#### Examples
333
334```js
335let buildNumber = DeviceInfo.getBuildNumber();
336// iOS: "89"
337// Android: "4"
338// Windows: ?
339```
340
341---
342
343### getBundleId()
344
345Gets the application bundle identifier.
346
347#### Examples
348
349```js
350let bundleId = DeviceInfo.getBundleId();
351// "com.example.AwesomeApp"
352```
353
354---
355
356### isCameraPresent()
357
358Tells if the device has any camera now.
359
360#### Examples
361
362```js
363DeviceInfo.isCameraPresent()
364 .then((isCameraPresent) => {
365 // true or false
366 })
367 .catch((cameraAccessException) => {
368 // is thrown if a camera device could not be queried or opened by the CameraManager on Android
369 });
370```
371
372#### Notes
373
374> - Hot add/remove of camera is supported.
375> - 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
376
377---
378
379### getCarrier()
380
381Gets the carrier name (network operator).
382
383#### Examples
384
385```js
386DeviceInfo.getCarrier().then((carrier) => {
387 // "SOFTBANK"
388});
389```
390
391---
392
393### getCodename()
394
395The current development codename, or the string "REL" if this is a release build.
396
397#### Examples
398
399```js
400DeviceInfo.getCodename().then((codename) => {
401 // "REL"
402});
403```
404
405---
406
407### getDevice()
408
409The name of the industrial design.
410
411#### Examples
412
413```js
414DeviceInfo.getDevice().then((device) => {
415 // "walleye"
416});
417```
418
419---
420
421### getDeviceId()
422
423Gets the device ID.
424
425#### Examples
426
427```js
428let deviceId = DeviceInfo.getDeviceId();
429// iOS: "iPhone7,2"
430// Android: "goldfish"
431// Windows: "Y3R94UC#AC4"
432```
433
434---
435
436### getDisplay()
437
438A build ID string meant for displaying to the user.
439
440#### Examples
441
442```js
443DeviceInfo.getDisplay().then((display) => {
444 // "OPM2.171026.006.G1"
445});
446```
447
448---
449
450### getDeviceName()
451
452Gets the device name.
453
454#### Examples
455
456```js
457DeviceInfo.getDeviceName().then((deviceName) => {
458 // iOS: "Becca's iPhone 6"
459 // Android: ?
460 // Windows: ?
461});
462```
463
464This 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]([url](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_device-information_user-assigned-device-name)) to access user-defined device name, otherwise a generic value is returned (ie. 'iPad', 'iPhone')
465
466---
467
468### getDeviceToken()
469
470Gets the device token (see [DeviceCheck](https://developer.apple.com/documentation/devicecheck)). Only available for iOS 11.0+ on real devices.
471This will reject the promise when getDeviceToken is not supported, be careful with exception handling.
472
473#### Examples
474
475```js
476DeviceInfo.getDeviceToken().then((deviceToken) => {
477 // iOS: "a2Jqsd0kanz..."
478});
479```
480
481---
482
483### getFirstInstallTime()
484
485Gets the time at which the app was first installed, in milliseconds.
486
487#### Examples
488
489```js
490DeviceInfo.getFirstInstallTime().then((firstInstallTime) => {
491 // Android: 1517681764528
492});
493```
494
495---
496
497### getFingerprint()
498
499A string that uniquely identifies this build.
500
501#### Examples
502
503```js
504DeviceInfo.getFingerprint().then((fingerprint) => {
505 // "google/walleye/walleye:8.1.0/OPM2.171026.006.G1/4820017:user/release-keys"
506});
507```
508
509---
510
511### getFontScale()
512
513Gets the device font scale.
514The 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
515This 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 )
516
517#### Examples
518
519```js
520DeviceInfo.getFontScale().then((fontScale) => {
521 // 1.2
522});
523```
524
525---
526
527### getFreeDiskStorage()
528
529Method that gets available storage size, in bytes, taking into account both root and data file systems calculation.
530
531On **iOS**, this method accepts the following optional arguments:
532- `'total'`: Uses `volumeAvailableCapacityKey`
533- `'important'`: Uses `volumeAvailableCapacityForImportantUsageKey`
534- `'opportunistic'`: Uses `volumeAvailableCapacityForOpportunisticUsageKey`
535
536For more details, refer to [Apple Documentation on Checking Volume Storage Capacity](https://developer.apple.com/documentation/foundation/urlresourcekey/checking_volume_storage_capacity).
537
538#### Examples
539
540```js
541DeviceInfo.getFreeDiskStorage().then((freeDiskStorage) => {
542 // Android: 17179869184
543 // iOS: 17179869184
544});
545
546DeviceInfo.getFreeDiskStorage('important').then((freeDiskStorage) => {
547 // iOS: 18198219342 (important storage)
548});
549```
550
551#### Notes
552
553The API used by this method for Android was changed in [v6.0.0](https://github.com/react-native-device-info/react-native-device-info/releases/tag/v6.0.0). The older version has been maintained below as `getFreeDiskStorageOld()`. On iOS, `getFreeDiskStorage()` and `getFreeDiskStorageOld()` return the same value.
554
555---
556
557### getFreeDiskStorageOld()
558
559Old implementation of method that gets available storage size, in bytes.
560
561#### Examples
562
563```js
564DeviceInfo.getFreeDiskStorageOld().then((freeDiskStorage) => {
565 // Android: 17179869184
566 // iOS: 17179869184
567});
568```
569
570#### Notes
571
572> From [developer.android.com](<https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()>):
573>
574> This method was deprecated in API level 29.
575>
576> Return the primary shared/external storage directory.
577>
578> Note: don't be confused by the word "external" here. This directory can better be thought as
579> media/shared storage. It is a filesystem that can hold a relatively large amount of data and
580> that is shared across all applications (does not enforce permissions). Traditionally this is
581> an SD card, but it may also be implemented as built-in storage in a device that is distinct
582> from the protected internal storage and can be mounted as a filesystem on a computer.
583
584---
585
586### getHardware()
587
588The name of the hardware (from the kernel command line or /proc).
589
590#### Examples
591
592```js
593DeviceInfo.getHardware().then(hardware => {
594 // "walleye"
595});
596```
597
598---
599
600### getHost()
601
602Hostname
603
604#### Examples
605
606```js
607DeviceInfo.getHost().then((host) => {
608 // "wprd10.hot.corp.google.com"
609});
610```
611
612---
613
614### getIpAddress()
615
616**Deprecated** Gets the device current IP address. (of wifi only)
617Switch to [react-native-netinfo/netinfo](https://github.com/react-native-netinfo/react-native-netinfo) or [react-native-network-info](https://github.com/pusherman/react-native-network-info)
618
619#### Examples
620
621```js
622DeviceInfo.getIpAddress().then((ip) => {
623 // "92.168.32.44"
624});
625```
626
627#### Android Permissions
628
629- [android.permission.ACCESS_WIFI_STATE](https://developer.android.com/reference/android/Manifest.permission.html#ACCESS_WIFI_STATE)
630
631#### Notes
632
633> Support for iOS was added in 0.22.0
634
635---
636
637### getIncremental()
638
639The internal value used by the underlying source control to represent this build.
640
641#### Examples
642
643```js
644DeviceInfo.getIncremental().then((incremental) => {
645 // "4820017"
646});
647```
648
649---
650
651### getInstallerPackageName()
652
653The internal value used by the underlying source control to represent this build.
654
655#### Examples
656
657```js
658DeviceInfo.getInstallerPackageName().then((installerPackageName) => {
659 // Play Store: "com.android.vending"
660 // Amazon: "com.amazon.venezia"
661 // Samsung App Store: "com.sec.android.app.samsungapps"
662 // iOS: "AppStore", "TestFlight", "Other"
663});
664```
665
666---
667
668### getInstallReferrer()
669
670Gets the referrer string upon application installation.
671
672#### Examples
673
674```js
675DeviceInfo.getInstallReferrer().then((installReferrer) => {
676 // If the app was installed from https://play.google.com/store/apps/details?id=com.myapp&referrer=my_install_referrer
677 // the result will be "my_install_referrer"
678});
679```
680
681---
682
683### getInstanceId()
684
685Gets the application instance ID.
686
687This attempts to get an instance ID from these sources, in this order:
688
689- a value under key `instanceId` in SharedPreferences file `react-native-device-info`
690- Firebase IID (if `firebaseBomVersion` or `firebaseIidVersion` is defined in gradle ext - **deprecated**)
691- GMS IID (if `googlePlayServicesIidVersion` or `googlePlayServicesVersion` is defined in gradle ext - **deprecated**)
692- a random UUID generated from java.util.UUID.randomUUID() and stored in SharedPreferences
693
694If 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.
695
696In 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.
697
698#### Examples
699
700```js
701DeviceInfo.getInstanceId().then((instanceId) => {
702 // Android: da4e0245-5d6c-402a-a07c-0c5349f229e2
703});
704```
705
706#### Notes
707
708> See https://developers.google.com/instance-id/
709
710---
711
712### getLastUpdateTime()
713
714Gets the time at which the app was last updated, in milliseconds.
715
716#### Examples
717
718```js
719DeviceInfo.getLastUpdateTime().then((lastUpdateTime) => {
720 // Android: 1517681764992
721});
722```
723
724---
725
726### getMacAddress()
727
728Gets the network adapter MAC address.
729
730#### Examples
731
732```js
733DeviceInfo.getMacAddress().then((mac) => {
734 // "E5:12:D8:E5:69:97"
735});
736```
737
738#### Android Permissions
739
740- [android.permission.ACCESS_WIFI_STATE](https://developer.android.com/reference/android/Manifest.permission.html#ACCESS_WIFI_STATE)
741
742#### Notes
743
744> iOS: This method always return "02:00:00:00:00:00" as retrieving the MAC address is [disabled since iOS 7](https://developer.apple.com/library/archive/releasenotes/General/WhatsNewIniOS/Articles/iOS7.html#//apple_ref/doc/uid/TP40013162-SW34)
745
746---
747
748### getManufacturer()
749
750Gets the device manufacturer.
751
752#### Examples
753
754```js
755DeviceInfo.getManufacturer().then((manufacturer) => {
756 // iOS: "Apple"
757 // Android: "Google"
758 // Windows: ?
759});
760```
761
762---
763
764### getMaxMemory()
765
766Returns the maximum amount of memory that the VM will attempt to use, in bytes.
767
768#### Examples
769
770```js
771DeviceInfo.getMaxMemory().then((maxMemory) => {
772 // 402653183
773});
774```
775
776---
777
778### getModel()
779
780Gets the device model.
781
782**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.
783
784#### Examples
785
786```js
787let model = DeviceInfo.getModel();
788// iOS: ?
789// Android: ?
790// Windows: ?
791```
792
793---
794
795### getPhoneNumber()
796
797The getPhoneNumber() has been removed. This method uses deprecated Android APIs. You can use react-native-sim-cards-manager to get the phone number.
798
799---
800
801### getPowerState()
802
803Gets 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.
804Displays a warning on iOS if battery monitoring not enabled, or if attempted on an emulator (where monitoring is not possible)
805
806#### Examples
807
808```js
809DeviceInfo.getPowerState().then((state) => {
810 // {
811 // batteryLevel: 0.759999,
812 // batteryState: 'unplugged',
813 // lowPowerMode: false,
814 // }
815});
816```
817
818---
819
820### getProduct()
821
822The name of the overall product.
823
824#### Examples
825
826```js
827DeviceInfo.getProduct().then((product) => {
828 // "walleye"
829});
830```
831
832---
833
834### getPreviewSdkInt()
835
836The developer preview revision of a prerelease SDK.
837
838#### Examples
839
840```js
841DeviceInfo.getPreviewSdkInt().then((previewSdkInt) => {
842 // 0
843});
844```
845
846---
847
848### getReadableVersion()
849
850Gets the application human readable version (same as getVersion() + '.' + getBuildNumber())
851
852#### Examples
853
854```js
855let readableVersion = DeviceInfo.getReadableVersion();
856// iOS: 1.0.1.32
857// Android: 1.0.1.234
858// Windows: ?
859```
860
861---
862
863### getSerialNumber()
864
865Gets the device serial number. Will be 'unknown' in almost all cases [unless you have a privileged app and you know what you're doing](<https://developer.android.com/reference/android/os/Build.html#getSerial()>).
866
867#### Examples
868
869```js
870DeviceInfo.getSerialNumber().then((serialNumber) => {
871 // iOS: unknown
872 // Android: ? (maybe a serial number, if your app is privileged)
873 // Windows: ? (a serial number, if your app has the "capability smbios")
874});
875```
876
877## Notes
878
879### capability smbios
880
881If you want to use this method in windows, you have to add smbios capability in your aplication. Please following this [documentation](https://docs.microsoft.com/en-us/windows/win32/sysinfo/access-smbios-information-from-a-universal-windows-app) for add the capability in your manifest file.
882
883---
884
885### getSecurityPatch()
886
887The user-visible security patch level.
888
889#### Examples
890
891```js
892DeviceInfo.getSecurityPatch().then((securityPatch) => {
893 // "2018-07-05"
894});
895```
896
897---
898
899### getSystemName()
900
901Gets the device OS name.
902
903#### Examples
904
905```js
906let systemName = DeviceInfo.getSystemName();
907// iOS: "iOS" on newer iOS devices "iPhone OS" on older devices (including older iPad models), "iPadOS" for iPads using iPadOS 15.0 or higher.
908// Android: "Android"
909// Windows: ?
910```
911
912---
913
914### getStartupTime()
915
916Gets the time at which the current app process was started, in milliseconds.
917
918#### Examples
919
920```js
921DeviceInfo.getStartupTime().then((startupTime) => {
922 // Android: 1517681764528
923 // iOS: 1517681764528
924});
925```
926
927---
928
929### getSystemVersion()
930
931Gets the device OS version.
932
933#### Examples
934
935```js
936let systemVersion = DeviceInfo.getSystemVersion();
937// iOS: "11.0"
938// Android: "7.1.1"
939// Windows: ?
940```
941
942---
943
944### getBuildId()
945
946Gets build number of the operating system.
947
948#### Examples
949
950```js
951DeviceInfo.getBuildId().then((buildId) => {
952 // iOS: "12A269"
953 // tvOS: not available
954 // Android: "13D15"
955 // Windows: not available
956});
957```
958
959---
960
961### getTags()
962
963Comma-separated tags describing the build.
964
965#### Examples
966
967```js
968DeviceInfo.getTags().then((tags) => {
969 // "release-keys, unsigned, debug",
970});
971```
972
973---
974
975### getType()
976
977The type of build.
978
979#### Examples
980
981```js
982DeviceInfo.getType().then((type) => {
983 // "user", "eng"
984});
985```
986
987---
988
989### getTotalDiskCapacity()
990
991Method that gets full disk storage size, in bytes, taking into account both root and data file systems calculation.
992
993#### Examples
994
995```js
996DeviceInfo.getTotalDiskCapacity().then((capacity) => {
997 // Android: 17179869184
998 // iOS: 17179869184
999});
1000```
1001
1002#### Notes
1003
1004The API used by this method for Android was changed in [v6.0.0](https://github.com/react-native-device-info/react-native-device-info/releases/tag/v6.0.0). The older version has been maintained below as `getTotalDiskCapacityOld()`. On iOS, `getTotalDiskCapacity()` and `getTotalDiskCapacityOld()` return the same value.
1005
1006---
1007
1008### getTotalDiskCapacityOld()
1009
1010Old implementation of method that gets full disk storage size, in bytes.
1011
1012#### Examples
1013
1014```js
1015DeviceInfo.getTotalDiskCapacityOld().then((capacity) => {
1016 // Android: 17179869184
1017 // iOS: 17179869184
1018});
1019```
1020
1021---
1022
1023### getTotalMemory()
1024
1025Gets the device total memory, in bytes.
1026
1027#### Examples
1028
1029```js
1030DeviceInfo.getTotalMemory().then((totalMemory) => {
1031 // 1995018240
1032});
1033```
1034
1035---
1036
1037### getUniqueId()
1038
1039_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)._
1040
1041Gets the device unique ID.
1042On Android it is currently identical to `getAndroidId()` in this module.
1043On iOS it uses the `DeviceUID` uid identifier.
1044On Windows it uses `Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation.id`.
1045
1046#### Examples
1047
1048```js
1049DeviceInfo.getUniqueId().then((uniqueId) => {
1050// iOS: "FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9"
1051// Android: "dd96dec43fb81c97"
1052// Windows: "{2cf7cb3c-da7a-d508-0d7f-696bb51185b4}"
1053});
1054```
1055
1056#### Notes
1057
1058> - iOS: This is [`IDFV`](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor) 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.
1059> Beware: The IDFV is calculated using your bundle identifier and thus will be different in app extensions.
1060> - android: Prior to Oreo, this id ([ANDROID_ID](https://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID)) will always be the same once you set up your phone.
1061> - android: [Google Play policy](https://support.google.com/googleplay/android-developer/answer/10144311), see "persistent device identifiers". [Huawei - AppGallery Review Guidelines](https://developer.huawei.com/consumer/en/doc/30202) see "permanent device identifier" and "obtaining user consent".
1062
1063---
1064
1065### syncUniqueId()
1066
1067This method is intended for iOS.
1068
1069This synchronizes uniqueId with [`IDFV`](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor) or sets new a random string.
1070
1071On iOS it uses the `DeviceUID` uid identifier.
1072On other platforms it just call `getUniqueId()` in this module.
1073
1074#### Examples
1075
1076```js
1077DeviceInfo.syncUniqueId().then((uniqueId) => {
1078 // iOS: "FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9"
1079 // Android: "dd96dec43fb81c97"
1080 // Windows: ?
1081});
1082```
1083
1084#### Notes
1085
1086> - 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`](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor) or a random string.
1087
1088---
1089
1090### getUsedMemory()
1091
1092Gets the app memory usage, in bytes.
1093
1094⚠️ [A note from the Android docs.](https://developer.android.com/reference/android/app/ActivityManager#getProcessMemoryInfo(int%5B%5D))
1095> Note: this method is only intended for debugging or building a user-facing process management UI.
1096
1097#### Examples
1098
1099```js
1100DeviceInfo.getUsedMemory().then((usedMemory) => {
1101 // 23452345
1102});
1103```
1104
1105---
1106
1107### getSupportedMediaTypeList()
1108This method gets the list of supported media codecs.
1109#### Examples
1110```js
1111DeviceInfo.getSupportedMediaTypeList().then((string[]) => {
1112 // ["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"]
1113});
1114```
1115---
1116
1117### getUserAgent()
1118
1119Gets the device User Agent.
1120
1121#### Examples
1122
1123```js
1124DeviceInfo.getUserAgent().then((userAgent) => {
1125 // 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"
1126 // tvOS: not available
1127 // 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"
1128 // Windows: ?
1129});
1130```
1131
1132---
1133
1134### getVersion()
1135
1136Gets the application version.
1137Take 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.
1138
1139#### Examples
1140
1141```js
1142let version = DeviceInfo.getVersion();
1143// iOS: "1.0"
1144// Android: "1.0" or "1.0.2-alpha.12"
1145// Windows: ?
1146```
1147
1148---
1149
1150### isAirplaneMode()
1151
1152Tells if the device is in Airplane Mode.
1153
1154#### Examples
1155
1156```js
1157DeviceInfo.isAirplaneMode().then((airplaneModeOn) => {
1158 // false
1159});
1160```
1161
1162#### Notes
1163
1164> - This only works if the remote debugger is disabled.
1165
1166---
1167
1168### isBatteryCharging()
1169
1170Tells if the battery is currently charging.
1171
1172#### Examples
1173
1174```js
1175DeviceInfo.isBatteryCharging().then((isCharging) => {
1176 // true or false
1177});
1178```
1179
1180---
1181
1182### isEmulator()
1183
1184Tells if the application is running in an emulator.
1185
1186#### Examples
1187
1188```js
1189DeviceInfo.isEmulator().then((isEmulator) => {
1190 // false
1191});
1192```
1193
1194---
1195
1196### isKeyboardConnected()
1197
1198Tells if the device has a keyboard connected.
1199
1200#### Examples
1201
1202```js
1203let isKeyboardConnected = DeviceInfo.isKeyboardConnected();
1204// true
1205```
1206
1207---
1208
1209### isPinOrFingerprintSet()
1210
1211Tells if a PIN number or a fingerprint was set for the device.
1212
1213#### Examples
1214
1215```js
1216DeviceInfo.isPinOrFingerprintSet().then((isPinOrFingerprintSet) => {
1217 if (!isPinOrFingerprintSet) {
1218 // ...
1219 }
1220});
1221```
1222
1223---
1224
1225### isTablet()
1226
1227Tells if the device is a tablet.
1228
1229#### Examples
1230
1231```js
1232let isTablet = DeviceInfo.isTablet();
1233// true
1234```
1235
1236---
1237
1238### isLowRamDevice()
1239
1240Tells if the device has low RAM.
1241
1242#### Examples
1243
1244```js
1245let isLowRamDevice = DeviceInfo.isLowRamDevice();
1246// true
1247```
1248
1249---
1250
1251### isDisplayZoomed()
1252
1253Tells if the user changed Display Zoom to Zoomed
1254
1255#### Examples
1256
1257```js
1258let isDisplayZoomed = DeviceInfo.isDisplayZoomed();
1259// true
1260```
1261
1262---
1263
1264### isTabletMode()
1265
1266Tells if the device is in tablet mode.
1267
1268#### Examples
1269
1270```js
1271let isTabletMode = DeviceInfo.isTabletMode();
1272// true
1273```
1274
1275---
1276
1277### isLandscape()
1278
1279Tells if the device is currently in landscape mode.
1280
1281#### Examples
1282
1283```js
1284DeviceInfo.isLandscape().then((isLandscape) => {
1285 // true
1286});
1287```
1288
1289---
1290
1291### isMouseConnected()
1292
1293Tells if the device has a mouse connected.
1294
1295#### Examples
1296
1297```js
1298let isMouseConnected = DeviceInfo.isMouseConnected();
1299// true
1300```
1301
1302---
1303
1304### hasGms()
1305
1306Tells if the device supports Google Mobile Services.
1307
1308#### Examples
1309
1310```js
1311DeviceInfo.hasGms().then((hasGms) => {
1312 // true
1313});
1314```
1315
1316---
1317
1318### hasHms()
1319
1320Tells if the device supports Huawei Mobile Services.
1321
1322#### Examples
1323
1324```js
1325DeviceInfo.hasHms().then((hasHms) => {
1326 // true
1327});
1328```
1329
1330---
1331
1332### hasNotch()
1333
1334Tells if the device has a notch.
1335
1336#### Examples
1337
1338```js
1339let hasNotch = DeviceInfo.hasNotch();
1340// true
1341```
1342
1343---
1344
1345### hasDynamicIsland()
1346
1347Tells if the device has a dynamic island.
1348
1349#### Examples
1350
1351```js
1352let hasDynamicIsland = DeviceInfo.hasDynamicIsland();
1353// true
1354```
1355
1356---
1357
1358### getDeviceType()
1359
1360Returns the device's type as a string, which will be one of:
1361
1362- `Handset`
1363- `Tablet`
1364- `Tv`
1365- `Desktop`
1366- `GamingConsole`
1367- `Headset`
1368- `unknown`
1369
1370#### Examples
1371
1372```js
1373let type = DeviceInfo.getDeviceType();
1374// 'Handset'
1375```
1376
1377---
1378
1379### supported32BitAbis()
1380
1381An ordered list of 32 bit ABIs supported by this device.
1382
1383#### Examples
1384
1385```js
1386DeviceInfo.supported32BitAbis().then((abis) => {
1387 // ["armeabi-v7a", "armeabi"]
1388});
1389```
1390
1391---
1392
1393### supported64BitAbis()
1394
1395An ordered list of 64 bit ABIs supported by this device.
1396
1397#### Examples
1398
1399```js
1400DeviceInfo.supported64BitAbis().then((abis) => {
1401 // ["arm64-v8a"]
1402});
1403```
1404
1405---
1406
1407### supportedAbis()
1408
1409Returns a list of supported processor architecture version
1410
1411#### Examples
1412
1413```js
1414DeviceInfo.supportedAbis().then((abis) => {
1415 // [ "arm64 v8", "Intel x86-64h Haswell", "arm64-v8a", "armeabi-v7a", "armeabi", "win_x86", "win_arm", "win_x64" ]
1416});
1417```
1418
1419---
1420
1421### hasSystemFeature(feature)
1422
1423Tells if the device has a specific system feature.
1424
1425#### Examples
1426
1427```js
1428DeviceInfo.hasSystemFeature('amazon.hardware.fire_tv').then((hasFeature) => {
1429 // true or false
1430});
1431```
1432
1433---
1434
1435### getSystemAvailableFeatures()
1436
1437Returns a list of available system features on Android.
1438
1439#### Examples
1440
1441```js
1442DeviceInfo.getSystemAvailableFeatures().then((features) => {
1443 // ["android.software.backup", "android.hardware.screen.landscape", "android.hardware.wifi", ...]
1444});
1445```
1446
1447### isLocationEnabled()
1448
1449Tells if the device has location services turned off at the device-level (NOT related to app-specific permissions)
1450
1451#### Examples
1452
1453```js
1454DeviceInfo.isLocationEnabled().then((enabled) => {
1455 // true or false
1456});
1457```
1458
1459### isHeadphonesConnected()
1460
1461Tells if the device is connected to wired headset or bluetooth headphones
1462
1463#### Examples
1464
1465```js
1466DeviceInfo.isHeadphonesConnected().then((enabled) => {
1467 // true or false
1468});
1469```
1470
1471### isWiredHeadphonesConnected()
1472
1473Tells if the device is connected to wired headset
1474
1475#### Examples
1476
1477```js
1478DeviceInfo.isWiredHeadphonesConnected().then((enabled) => {
1479 // true or false
1480});
1481```
1482
1483### isBluetoothHeadphonesConnected()
1484
1485Tells if the device is connected to bluetooth headset
1486
1487#### Examples
1488
1489```js
1490DeviceInfo.isBluetoothHeadphonesConnected().then((enabled) => {
1491 // true or false
1492});
1493```
1494
1495### getAvailableLocationProviders()
1496
1497Returns an object of **platform-specfic** location providers/servcies, with `boolean` value whether or not they are currently available.
1498
1499> NOTE: This function requires access to the Location permission on Android
1500
1501#### Android Example
1502
1503```js
1504DeviceInfo.getAvailableLocationProviders().then((providers) => {
1505 // {
1506 // gps: true
1507 // network: true
1508 // passive: true
1509 // }
1510});
1511```
1512
1513#### iOS Example
1514
1515```js
1516DeviceInfo.getAvailableLocationProviders().then((providers) => {
1517 // {
1518 // headingAvailable: false
1519 // isRangingAvailable: false
1520 // locationServicesEnabled: true
1521 // significantLocationChangeMonitoringAvailable: true
1522 // }
1523});
1524```
1525
1526### getBrightness()
1527
1528Gets the current brightness level of the device's main screen. Currently iOS only. Returns a number between 0.0 and 1.0, inclusive.
1529
1530#### Examples
1531
1532```js
1533DeviceInfo.getBrightness().then((brightness) => {
1534 // iOS: 0.6
1535});
1536```
1537
1538## Hooks & Events
1539
1540Supported in Windows, iOS & Android (web support for battery/charging-related APIs).
1541
1542### useBatteryLevel or RNDeviceInfo_batteryLevelDidChange
1543
1544Fired when the battery level changes; sent no more frequently than once per minute.
1545
1546#### Examples
1547
1548```js
1549import { useBatteryLevel } from 'react-native-device-info';
1550
1551const batteryLevel = useBatteryLevel(); // 0.759999
1552
1553<Text>{batteryLevel}</Text>;
1554```
1555
1556```js
1557import { NativeEventEmitter, NativeModules } from 'react-native';
1558const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo);
1559
1560deviceInfoEmitter.addListener('RNDeviceInfo_batteryLevelDidChange', (level) => {
1561 // 0.759999
1562});
1563```
1564
1565---
1566
1567### useBatteryLevelIsLow or RNDeviceInfo_batteryLevelIsLow
1568
1569Fired when the battery level is considered low (multiple times untill charged)
1570
1571| Platform | Percentage |
1572| -------- | ---------- |
1573| iOS | 20 |
1574| Android | 15 |
1575| Web | 20 |
1576| Windows | 20 |
1577
1578#### Examples
1579
1580```js
1581import { useBatteryLevelIsLow } from 'react-native-device-info';
1582
1583const batteryLevelIsLow = useBatteryLevelIsLow(); // 0.19
1584
1585<Text>{batteryLevelIsLow}</Text>;
1586```
1587
1588```js
1589import { NativeEventEmitter, NativeModules } from 'react-native';
1590const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo);
1591
1592deviceInfoEmitter.addListener('RNDeviceInfo_batteryLevelIsLow', (level) => {
1593 // 0.19
1594});
1595```
1596
1597---
1598
1599### usePowerState or RNDeviceInfo_powerStateDidChange
1600
1601Fired when the battery state changes or device enters in the power saving mode, for example when the device enters charging mode or is unplugged.
1602
1603#### Examples
1604
1605```js
1606import { usePowerState } from 'react-native-device-info';
1607
1608const powerState = usePowerState();
1609 // {
1610 // batteryLevel: 0.759999,
1611 // batteryState: 'unplugged',
1612 // lowPowerMode: false,
1613 // }
1614
1615<Text>{powerState}</Text>;
1616```
1617
1618```js
1619import { NativeEventEmitter, NativeModules } from 'react-native'
1620const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo)
1621
1622deviceInfoEmitter.addListener('RNDeviceInfo_powerStateDidChange', { powerState } => {
1623 // {
1624 // batteryLevel: 0.759999,
1625 // batteryState: 'unplugged',
1626 // lowPowerMode: false,
1627 // }
1628});
1629```
1630
1631---
1632
1633### useFirstInstallTime
1634
1635Gets the time at which the app was first installed, in milliseconds.
1636
1637#### Example
1638
1639```jsx
1640import { useFirstInstallTime } from 'react-native-device-info';
1641
1642const { loading, result } = useFirstInstallTime(); // { loading: true, result: 1517681764528}
1643
1644<Text>{loading ? 'loading...' : result}</Text>;
1645```
1646
1647---
1648
1649### useDeviceName
1650
1651Gets the device name.
1652
1653#### Example
1654
1655```jsx
1656import { useDeviceName } from 'react-native-device-info';
1657
1658const { loading, result } = useDeviceName(); // { loading: true, result: "Becca's iPhone 6"}
1659
1660<Text>{loading ? 'loading...' : result}</Text>;
1661```
1662
1663---
1664
1665### useHasSystemFeature
1666
1667Tells if the device has a specific system feature.
1668
1669#### Example
1670
1671```jsx
1672import { useHasSystemFeature } from 'react-native-device-info';
1673
1674const { loading, result } = useHasSystemFeature('amazon.hardware.fire_tv'); // { loading: true, result: false }
1675
1676<Text>{loading ? 'loading...' : result}</Text>;
1677```
1678
1679---
1680
1681### useIsEmulator
1682
1683Get whether the application is running in an emulator.
1684
1685#### Example
1686
1687```jsx
1688import { useIsEmulator } from 'react-native-device-info';
1689
1690const { loading, result } = useIsEmulator(); // { loading: true, result: false }
1691
1692<Text>{loading ? 'loading...' : result}</Text>;
1693```
1694
1695---
1696
1697### useManufacturer
1698
1699Gets the device manufacturer.
1700
1701#### Example
1702
1703```jsx
1704import { useManufacturer } from 'react-native-device-info';
1705
1706const { loading, result } = useManufacturer(); // { loading: true, result: "Apple"}
1707
1708<Text>{loading ? 'loading...' : result}</Text>;
1709```
1710
1711---
1712
1713### useIsHeadphonesConnected
1714
1715Tells if the device is connected to wired headset or bluetooth headphones.
1716
1717This hook subscribes to the event, `RNDeviceInfo_headphoneConnectionDidChange` , and updates the `result` field accordingly.
1718
1719#### Example
1720
1721```jsx
1722import { useIsHeadphonesConnected } from 'react-native-device-info';
1723
1724const { loading, result } = useIsHeadphonesConnected(); // { loading: true, result: false}
1725
1726<Text>{loading ? 'loading...' : result}</Text>;
1727```
1728
1729---
1730
1731### useIsWiredHeadphonesConnected
1732
1733Tells if the device is connected to wired headset.
1734
1735This hook subscribes to the event, `RNDeviceInfo_headphoneWiredConnectionDidChange` , and updates the `result` field accordingly.
1736
1737#### Example
1738
1739```jsx
1740import { useIsWiredHeadphonesConnected } from 'react-native-device-info';
1741
1742const { loading, result } = useIsWiredHeadphonesConnected(); // { loading: true, result: false}
1743
1744<Text>{loading ? 'loading...' : result}</Text>;
1745```
1746
1747---
1748
1749### useIsBluetoothHeadphonesConnected
1750
1751Tells if the device is connected to bluetooth headphones.
1752
1753This hook subscribes to the event, `RNDeviceInfo_headphoneBluetoothConnectionDidChange` , and updates the `result` field accordingly.
1754
1755#### Example
1756
1757```jsx
1758import { useIsBluetoothHeadphonesConnected } from 'react-native-device-info';
1759
1760const { loading, result } = useIsBluetoothHeadphonesConnected(); // { loading: true, result: false}
1761
1762<Text>{loading ? 'loading...' : result}</Text>;
1763```
1764
1765---
1766
1767### useBrightness
1768
1769Gets the current brightness level of the device's main screen. Currently iOS only. Returns a number between 0.0 and 1.0, inclusive.
1770
1771This hook subscribes to the event, `RNDeviceInfo_brightnessDidChange` , and updates the `brightness` field accordingly.
1772
1773#### Example
1774
1775```jsx
1776import { useBrightness } from 'react-native-device-info';
1777
1778const brightness = useBrightness(); // 0.46578987897654567
1779
1780<Text>{brightness}</Text>;
1781```
1782
1783```js
1784import { NativeEventEmitter, NativeModules } from 'react-native';
1785
1786const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo);
1787
1788deviceInfoEmitter.addListener('RNDeviceInfo_brightnessDidChange', (brightness) => {
1789 // 0.46578987897654567
1790});
1791```
1792
1793=======
1794
1795## Native interoperatibily
1796
1797If you need to check for device type from the native side, you can use the following:
1798
1799```java
1800import com.learnium.resolver.DeviceTypeResolver
1801
1802...
1803deviceTypeResolver = new DeviceTypeResolver(context);
1804...
1805//Check if the device is a Tablet:
1806if(deviceTypeResolver.isTablet){
1807 ...
1808}else{
1809 ...
1810}
1811```
1812
1813## Troubleshooting
1814
1815When installing or using `react-native-device-info`, you may encounter the following problems:
1816
1817<details>
1818 <summary>[android] - Unable to merge dex / Multiple dex files / Problems with `com.google.android.gms`</summary>
1819
1820`react-native-device-info` uses `com.google.android.gms:play-services-gcm` to provide [getInstanceId()](#getinstanceid).
1821This can lead to conflicts when building the Android application.
1822
1823If you're using a different version of `com.google.android.gms:play-services-gcm` in your app, you can define the
1824`googlePlayServicesVersion` gradle variable in your `build.gradle` file to tell `react-native-device-info` what version
1825it should require. See the example project included here for a sample.
1826
1827If 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
1828ignore this dependency in your gradle file:
1829
1830```groovy
1831 compile(project(':react-native-device-info')) {
1832 exclude group: 'com.google.android.gms'
1833}
1834```
1835
1836</details>
1837
1838<details>
1839 <summary>[ios] - ld: library not found for -lRNDeviceInfo-tvOS</summary>
1840
1841Seems 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`.
1842
1843</details>
1844
1845<details>
1846 <summary>[ios] - [NetworkInfo] Descriptors query returned error: Error Domain=NSCocoaErrorDomain Code=4099
1847 “The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated.”</summary>
1848
1849This is a system level log that may be turned off by executing:
1850`xcrun simctl spawn booted log config --mode "level:off" --subsystem com.apple.CoreTelephony`.
1851To undo the command, you can execute:
1852`xcrun simctl spawn booted log config --mode "level:info" --subsystem com.apple.CoreTelephony`
1853
1854</details>
1855
1856<details>
1857 <summary>[ios] - Multiple versions of React when using CocoaPods
1858 "tries to require 'react-native' but there are several files providing this module"</summary>
1859
1860### RN<=59 You may need to adjust your Podfile like this if you use Cocoapods and have undefined symbols or duplicate React definitions
1861
1862```ruby
1863target 'yourTargetName' do
1864 # See http://facebook.github.io/react-native/docs/integration-with-existing-apps.html#configuring-cocoapods-dependencies
1865 pod 'React', :path => '../node_modules/react-native', :subspecs => [
1866 'Core',
1867 'CxxBridge', # Include this for RN >= 0.47
1868 'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
1869 'RCTText',
1870 'RCTNetwork',
1871 'RCTWebSocket', # Needed for debugging
1872 'RCTAnimation', # Needed for FlatList and animations running on native UI thread
1873 # Add any other subspecs you want to use in your project
1874 ]
1875
1876 # Explicitly include Yoga if you are using RN >= 0.42.0
1877 pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
1878
1879 # Third party deps podspec link - you may have multiple pods here, just an example
1880 pod 'RNDeviceInfo', path: '../node_modules/react-native-device-info'
1881
1882end
1883
1884# if you see errors about React duplicate definitions, this fixes it. The same works for yoga.
1885post_install do |installer|
1886 installer.pods_project.targets.each do |target|
1887 if target.name == "React"
1888 target.remove_from_project
1889 end
1890 end
1891end
1892```
1893
1894</details>
1895
1896<details>
1897 <summary>[tests] - Cannot run my test suite when using this library</summary>
1898
1899`react-native-device-info` contains native code, and needs to be mocked. Jest Snapshot support may work though.
1900
1901If 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:
1902
1903```js
1904setupFiles: ['<rootDir>/jest.setup.js'];
1905```
1906
1907You should then add the following to your Jest setup file to mock the DeviceInfo Native Module:
1908
1909```js
1910import mockRNDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock';
1911
1912jest.mock('react-native-device-info', () => mockRNDeviceInfo);
1913```
1914
1915Checkout the example project for more information.
1916
1917</details>
1918<details>
1919 <summary>[warnings] - I get too many warnings (battery state, etc)</summary>
1920
1921Some 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:
1922
1923```javascript
1924import { LogBox } from 'react-native';
1925LogBox.ignoreLogs(['Battery state']);
1926```
1927
1928</details>
1929
1930## Release Notes
1931
1932See the [CHANGELOG.md](https://github.com/react-native-device-info/react-native-device-info/blob/master/CHANGELOG.md).
1933
1934## Contributing
1935
1936Please see the [`contributing guide`](/CONTRIBUTING.md).
1937
1938## react-native-dom
1939
1940As a courtesy to developers, this library was made compatible in v0.21.6 with [react-native-dom](https://github.com/vincentriemer/react-native-dom) and [react-native-web](https://github.com/necolas/react-native-web) by providing an empty polyfill in order to avoid breaking builds.
1941
1942Only [getUserAgent()](#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.