UNPKG

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