React native device info library: How to use it to get the device information

Device properties are very important for developer to optimise the app performances and providing extra information for tracing app crashes. For example, the total and used RAM, the manufacturer of the device and even if the device is charging at runtime, etc. These information are very important for making a business decision. So that, in this article, we will give you a guide how to use React Native device info library to get the device information.

Setup – React native device info

Above all, Install it with your own package manager:

npm install --save react-native-device-info

React native device info

Android Specific properties

import DeviceInfo from 'react-native-device-info'; // Android: 38c26a0bebda7fc2 console.log("getAndroidId(): ", await DeviceInfo.getAndroidId()) // Android: 29 console.log("getApiLevel(): ", await DeviceInfo.getApiLevel()) // Android: *Empty string... console.log("getBaseOs(): ", await DeviceInfo.getBaseOs()) // Android: b4s4-0.2-6355063 console.log("getBootloader(): ", await DeviceInfo.getBootloader()) // Android: true console.log("isCameraPresent(): ", await DeviceInfo.isCameraPresent()) // Android: REL console.log("getCodename(): ", await DeviceInfo.getCodename()) // Android: sargo console.log("getDevice(): ", await DeviceInfo.getDevice()) // Android: QQ3A.200605.002 console.log("getDisplay(): ", await DeviceInfo.getDisplay()) // Android: 1594950417038 console.log("getFirstInstallTime(): ", await DeviceInfo.getFirstInstallTime()) // Android: google/sargo/sargo:10/QQ3A.200605.002/6416773:user/release-keys console.log("getFingerprint(): ", await DeviceInfo.getFingerprint()) // Android: sargo console.log("getHardware(): ", await DeviceInfo.getHardware()) // Android: abfarm-00906 console.log("getHost(): ", await DeviceInfo.getHost()) // Android: 6416773 console.log("getIncremental(): ", await DeviceInfo.getIncremental()) // Android: unknown console.log("getInstallerPackageName(): ", await DeviceInfo.getInstallerPackageName()) // Android: utm_source=google-play&utm_medium=organic console.log("getInstallReferrer(): ", await DeviceInfo.getInstallReferrer()) // Android: dBkzW2cCRMirU1oSLf6iym console.log("getInstanceId(): ", await DeviceInfo.getInstanceId()) // Android: 1594953973652 console.log("getLastUpdateTime(): ", await DeviceInfo.getLastUpdateTime()) // Android: 201326592 console.log("getMaxMemory(): ", await DeviceInfo.getMaxMemory()) // Android: unknown *(Since no SIM card) console.log("getPhoneNumber(): ", await DeviceInfo.getPhoneNumber()) // Android: sargo console.log("getProduct(): ", await DeviceInfo.getProduct()) // Android: 0 console.log("getPreviewSdkInt(): ", await DeviceInfo.getPreviewSdkInt()) // Android: unknown console.log("getSerialNumber(): ", await DeviceInfo.getSerialNumber()) // Android: 2020-06-05 console.log("getSecurityPatch(): ", await DeviceInfo.getSecurityPatch()) // Android: (101) ["android.hardware.sensor.proximity", "com.verizon.hardware.telephony.lte", "com.verizon.hardware.telephony.ehrpd", "android.hardware.sensor.accelerometer", "android.hardware.faketouch", "android.hardware.telephony.euicc", "android.hardware.usb.accessory", "android.hardware.telephony.cdma", "android.software.backup", "android.hardware.touchscreen", "android.hardware.touchscreen.multitouch", "android.software.print", "android.software.activities_on_secondary_displays", "android.hardware.wifi.rtt", "com.google.android.feature.PIXEL_2017_EXPERIENCE", "android.software.voice_recognizers", "android.software.picture_in_picture", "android.hardware.fingerprint", "android.hardware.sensor.gyroscope", "android.hardware.audio.low_latency", "android.software.cant_save_state", "com.google.android.feature.PIXEL_2018_EXPERIENCE", "android.hardware.opengles.aep", "android.hardware.bluetooth", "android.hardware.camera.autofocus", "com.google.android.feature.GOOGLE_BUILD", "android.hardware.telephony.gsm", "android.hardware.telephony.ims", "android.software.sip.voip", "android.hardware.usb.host", "android.hardware.audio.output", "android.software.verified_boot", "android.hardware.camera.flash", "android.hardware.camera.front", "android.hardware.sensor.hifi_sensors", "android.hardware.strongbox_keystore", "android.hardware.screen.portrait", "android.hardware.nfc", "com.google.android.feature.TURBO_PRELOAD", "android.hardware.sensor.stepdetector", "android.software.home_screen", "android.hardware.microphone", "android.software.autofill", "android.software.securely_removes_users", "com.google.android.feature.PIXEL_EXPERIENCE", "android.hardware.bluetooth_le", "android.hardware.sensor.compass", "android.hardware.touchscreen.multitouch.jazzhand", "android.hardware.sensor.barometer", "android.software.app_widgets", "android.hardware.telephony.carrierlock", "android.software.input_methods", "android.hardware.sensor.light", "android.hardware.vulkan.version", "android.software.companion_device_setup", "android.software.device_admin", "com.google.android.feature.WELLBEING", "android.hardware.wifi.passpoint", "android.hardware.camera", "com.google.android.feature.ZERO_TOUCH", "android.hardware.screen.landscape", "android.software.device_id_attestation", "android.hardware.ram.normal", "com.google.android.feature.PIXEL_2019_MIDYEAR_EXPERIENCE", "android.software.managed_users", "android.software.webview", "android.hardware.sensor.stepcounter", "android.hardware.camera.capability.manual_post_processing", "android.hardware.camera.any", "android.hardware.camera.capability.raw", "android.hardware.vulkan.compute", "android.software.connectionservice", "android.hardware.touchscreen.multitouch.distinct", "android.hardware.location.network", "android.software.cts", "android.software.sip", "android.hardware.camera.capability.manual_sensor", "com.google.hardware.camera.easel_2018", "com.google.android.apps.dialer.SUPPORTED", "android.hardware.camera.level.full", "com.google.android.apps.photos.PIXEL_2019_MIDYEAR_PRELOAD", "android.hardware.wifi.direct", "android.software.live_wallpaper", "com.google.android.feature.GOOGLE_EXPERIENCE", "android.software.ipsec_tunnels", "com.google.android.feature.EXCHANGE_6_2", "android.hardware.sensor.assist", "android.hardware.audio.pro", "android.hardware.nfc.hcef", "android.hardware.nfc.uicc", "android.hardware.location.gps", "android.software.midi", "android.hardware.nfc.any", "android.hardware.nfc.hce", "android.hardware.wifi", "android.hardware.location", "android.hardware.vulkan.level", "android.hardware.wifi.aware", "android.software.secure_lock_screen", "android.hardware.telephony", …] console.log("getSystemAvailableFeatures(): ", await DeviceInfo.getSystemAvailableFeatures()) // Android: release-keys console.log("getTags(): ", await DeviceInfo.getTags()) // Android: user console.log("getType(): ", await DeviceInfo.getType()) // Android: false console.log("hasSystemFeature(): ", await DeviceInfo.hasSystemFeature()) // Android: false console.log("isAirplaneMode(): ", await DeviceInfo.isAirplaneMode()) // Android: (2) ["armeabi-v7a", "armeabi"] console.log("supported32BitAbis(): ", await DeviceInfo.supported32BitAbis()) // Android: ["arm64-v8a"] console.log("supported64BitAbis(): ", await DeviceInfo.supported64BitAbis())

iOS Specific properties

// iOS: AgAAACIGFMN4MeDfCjHM0n9...
console.log("getDeviceToken(): ", await DeviceInfo.getDeviceToken())

// iOS: 27E91FEC-XXXX-XXXX-XXXX-XXXXXXXXXXXX
console.log("syncUniqueId(): ", await DeviceInfo.syncUniqueId())

Android & iOS Shared Properties

// Android: Example app
// iOS: Example app
console.log("getApplicationName(): ", await DeviceInfo.getApplicationName())

// Android: {}
/*
iOS: {
   significantLocationChangeMonitoringAvailable: true, 
   isRangingAvailable: true, 
   locationServicesEnabled: true, 
   headingAvailable: true
}
*/
console.log("getAvailableLocationProviders(): ", await DeviceInfo.getAvailableLocationProviders())

// Android: QQ3A.200605.002
// iOS: 17F80
console.log("getBuildId(): ", await DeviceInfo.getBuildId())

// Android: 1
// iOS: 1
console.log("getBatteryLevel(): ", await DeviceInfo.getBatteryLevel())

// Android: google
// iOS: Apple
console.log("getBrand(): ", await DeviceInfo.getBrand())

// Android: 1
// iOS: 1
console.log("getBuildNumber(): ", await DeviceInfo.getBuildNumber())

// Android: com.example.app
// iOS: com.example.app
console.log("getBundleId(): ", await DeviceInfo.getBundleId())

// Android: *Empty string when no SIM card
// iOS: 1O1O / csl
console.log("getCarrier(): ", await DeviceInfo.getCarrier())

// Android: sargo
// iOS: iPhone11,2
console.log("getDeviceId(): ", await DeviceInfo.getDeviceId())

// Android: Handset
// iOS: Handset
console.log("getDeviceType(): ", await DeviceInfo.getDeviceType())

// Android: Pixel 3a
// iOS: Testing Device
console.log("getDeviceName(): ", await DeviceInfo.getDeviceName())

// Android: 1
// iOS: 1.1200000047683716
console.log("getFontScale(): ", await DeviceInfo.getFontScale())

// Android: 42753028096
// iOS: 413816471552
console.log("getFreeDiskStorage(): ", await DeviceInfo.getFreeDiskStorage())

// Android: 192.168.1.101
// iOS: 192.168.1.101
console.log("getIpAddress(): ", await DeviceInfo.getIpAddress())

// Android: CE:31:93:AA:AA:1B
// iOS: 02:00:00:00:00:00
console.log("getMacAddress(): ", await DeviceInfo.getMacAddress())

// Android: Google
// iOS: Apple
console.log("getManufacturer(): ", await DeviceInfo.getManufacturer())

// Android: Pixel 3a
// iOS: iPhone XS
console.log("getModel(): ", await DeviceInfo.getModel())

/*
Android: {
  lowPowerMode: false, 
  batteryLevel: 1, 
  batteryState: "full"
}
*/
/*
iOS: {
  batteryState: "charging", 
  batteryLevel: 1, 
  lowPowerMode: false
}
*/
console.log("getPowerState(): ", await DeviceInfo.getPowerState())

// Android: 1.0.1
// iOS: 1.0.1
console.log("getReadableVersion(): ", await DeviceInfo.getReadableVersion())

// Android: Android
// iOS: iOS
console.log("getSystemName(): ", await DeviceInfo.getSystemName())

// Android: 10
// iOS: 13.5.1
console.log("getSystemVersion(): ", await DeviceInfo.getSystemVersion())

// Android: 816848896
// iOS: 511937040384
console.log("getTotalDiskCapacity(): ", await DeviceInfo.getTotalDiskCapacity())

// Android: 3768160256
// iOS: 3953475584
console.log("getTotalMemory(): ", await DeviceInfo.getTotalMemory())

// Android: c26a0bebda7fc2
// iOS: 27E91FEC-A27D-4138-B584-55195270446D
console.log("getUniqueId(): ", await DeviceInfo.getUniqueId())

// Android: 10127336
// iOS: 80871424
console.log("getUsedMemory(): ", await DeviceInfo.getUsedMemory())

// Android: Mozilla/5.0 (Linux; Android 10; Pixel 3a Build/QQ3A.200605.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.106 Mobile Safari/537.36
// iOS: Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148
console.log("getUserAgent(): ", await DeviceInfo.getUserAgent())

// Android: 1.0
// iOS: 1.0
console.log("getVersion(): ", await DeviceInfo.getVersion())

// Android: false
// iOS: true
console.log("hasNotch(): ", await DeviceInfo.hasNotch())

// Android: false
// iOS: true
console.log("isBatteryCharging(): ", await DeviceInfo.isBatteryCharging())

// Android: false
// iOS: true
console.log("isEmulator(): ", await DeviceInfo.isEmulator())

// Android: false
// iOS: true
console.log("isLandscape(): ", await DeviceInfo.isLandscape())

// Android: false
// iOS: true
console.log("isLocationEnabled(): ", await DeviceInfo.isLocationEnabled())

// Android: false
// iOS: true
console.log("isHeadphonesConnected(): ", await DeviceInfo.isHeadphonesConnected())

// Android: false
// iOS: true
console.log("isPinOrFingerprintSet(): ", await DeviceInfo.isPinOrFingerprintSet())

// Android: false
// iOS: true
console.log("isTablet(): ", await DeviceInfo.isTablet())

// Android: (3) ["arm64-v8a", "armeabi-v7a", "armeabi"]
// iOS: ["ARM64E"]
console.log("supportedAbis(): ", await DeviceInfo.supportedAbis())

To Run the React Native App by React native device info

Firstly, open the terminal again and jump into your project using.

cd ProjectName

Secondly, to run the project on an Android Virtual Device or on real debugging device

react-native run-android

Thirdly, or on the iOS Simulator by running (macOS only)

react-native run-ios

Read more

React native switch: Useful understanding for the developers

In Conclusion

All in all, this blog is a lot of helpful knowledge of React native device info, we hope you can take advantage of it. Then, adapt it successfully for your business. In case you have any iquiry or face any issue with this topic, don’t hesitate to CONTACT US now. With over 14 years of experience as well as being one of the most famous outsourcing companies all around the world, ArrowHiTech will surely give the wonderful React Native development services for your company.

Tags

Share