UNPKG

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