Get device information using react-native
npx @tessl/cli install tessl/npm-react-native-device-info@14.0.00
# React Native Device Info
1
2
React Native Device Info is a comprehensive cross-platform library that provides access to device and system information across iOS, Android, Windows, and web platforms. It offers a rich API for retrieving device details including hardware specifications, system information, unique identifiers, battery status, network information, and device capabilities with both synchronous and asynchronous data retrieval patterns.
3
4
## Package Information
5
6
- **Package Name**: react-native-device-info
7
- **Package Type**: npm
8
- **Language**: TypeScript
9
- **Installation**: `npm install react-native-device-info`
10
11
## Core Imports
12
13
```typescript
14
import DeviceInfo from 'react-native-device-info';
15
16
// Or ES6+ destructured imports
17
import {
18
getUniqueId,
19
getManufacturer,
20
getBatteryLevel,
21
isTablet,
22
useBatteryLevel
23
} from 'react-native-device-info';
24
```
25
26
For CommonJS:
27
28
```javascript
29
const DeviceInfo = require('react-native-device-info');
30
31
// Or destructured
32
const { getUniqueId, getManufacturer } = require('react-native-device-info');
33
```
34
35
## Basic Usage
36
37
```typescript
38
import {
39
getUniqueId,
40
getManufacturer,
41
getBatteryLevel,
42
isTablet,
43
getSystemVersion
44
} from 'react-native-device-info';
45
46
// Basic device identification
47
const deviceId = await getUniqueId();
48
const manufacturer = await getManufacturer();
49
const isTabletDevice = isTablet();
50
51
// System information
52
const osVersion = getSystemVersion();
53
54
// Battery status
55
const batteryLevel = await getBatteryLevel();
56
57
console.log(`Device: ${manufacturer} (${deviceId})`);
58
console.log(`OS Version: ${osVersion}`);
59
console.log(`Device Type: ${isTabletDevice ? 'Tablet' : 'Phone'}`);
60
console.log(`Battery: ${Math.round(batteryLevel * 100)}%`);
61
```
62
63
## Architecture
64
65
React Native Device Info is built around several key architectural components:
66
67
- **Platform Detection**: Automatic platform-specific implementation routing for iOS, Android, Windows, and web
68
- **Sync/Async Patterns**: Dual API approach with both synchronous and asynchronous versions of most methods
69
- **Memoization**: Built-in caching system for frequently accessed device properties to improve performance
70
- **React Hooks Integration**: Custom hooks for real-time monitoring of dynamic device states
71
- **Graceful Fallbacks**: Default values ("unknown", -1, false, []) for unsupported platforms or unavailable features
72
- **Type Safety**: Comprehensive TypeScript definitions with platform-specific type narrowing
73
74
## Capabilities
75
76
### Device Identification
77
78
Core device identification functionality for retrieving unique identifiers, device details, and hardware information. Essential for analytics, device tracking, and platform-specific behavior.
79
80
```typescript { .api }
81
function getUniqueId(): Promise<string>;
82
function getUniqueIdSync(): string;
83
function getDeviceId(): string;
84
function getModel(): string;
85
function getBrand(): string;
86
function getManufacturer(): Promise<string>;
87
function getManufacturerSync(): string;
88
```
89
90
[Device Identification](./device-identification.md)
91
92
### System Information
93
94
System and operating system information including OS version, build details, and platform-specific system properties. Critical for compatibility checks and platform-specific feature detection.
95
96
```typescript { .api }
97
function getSystemName(): string;
98
function getSystemVersion(): string;
99
function getBuildId(): Promise<string>;
100
function getBuildIdSync(): string;
101
function getApiLevel(): Promise<number>; // Android only
102
function getApiLevelSync(): number; // Android only
103
function supportedAbis(): Promise<string[]>;
104
function supportedAbisSync(): string[];
105
function hasSystemFeature(feature: string): Promise<boolean>; // Android only
106
function hasSystemFeatureSync(feature: string): boolean; // Android only
107
function getStartupTime(): Promise<number>;
108
function getStartupTimeSync(): number;
109
```
110
111
[System Information](./system-information.md)
112
113
### Application Information
114
115
Application metadata including version information, installation details, and app-specific identifiers. Useful for app analytics, version checking, and installation tracking.
116
117
```typescript { .api }
118
function getApplicationName(): string;
119
function getBundleId(): string;
120
function getVersion(): string;
121
function getBuildNumber(): string;
122
function getReadableVersion(): string;
123
function getFirstInstallTime(): Promise<number>;
124
function getFirstInstallTimeSync(): number;
125
```
126
127
[Application Information](./application-information.md)
128
129
### Memory and Storage
130
131
Memory usage and storage capacity information for performance monitoring and storage management. Essential for optimizing app performance and managing device resources.
132
133
```typescript { .api }
134
function getUsedMemory(): Promise<number>;
135
function getUsedMemorySync(): number;
136
function getTotalMemory(): Promise<number>;
137
function getTotalMemorySync(): number;
138
function getFreeDiskStorage(): Promise<number>;
139
function getFreeDiskStorageSync(): number;
140
function getTotalDiskCapacity(): Promise<number>;
141
function getTotalDiskCapacitySync(): number;
142
```
143
144
[Memory and Storage](./memory-storage.md)
145
146
### Battery and Power
147
148
Battery status and power management information for power-aware applications and battery optimization. Critical for apps that need to adapt behavior based on battery state.
149
150
```typescript { .api }
151
function getBatteryLevel(): Promise<number>;
152
function getBatteryLevelSync(): number;
153
function getPowerState(): Promise<Partial<PowerState>>;
154
function getPowerStateSync(): Partial<PowerState>;
155
function isBatteryCharging(): Promise<boolean>;
156
function isBatteryChargingSync(): boolean;
157
158
interface PowerState {
159
batteryLevel: number;
160
batteryState: BatteryState;
161
lowPowerMode: boolean;
162
[key: string]: any;
163
}
164
165
type BatteryState = 'unknown' | 'unplugged' | 'charging' | 'full';
166
```
167
168
[Battery and Power](./battery-power.md)
169
170
### Network and Connectivity
171
172
Network and connectivity information including IP addresses, carrier information, and connection status. Important for network-aware applications and connectivity debugging.
173
174
```typescript { .api }
175
function getIpAddress(): Promise<string>;
176
function getIpAddressSync(): string;
177
function getCarrier(): Promise<string>;
178
function getCarrierSync(): string;
179
function getMacAddress(): Promise<string>;
180
function getMacAddressSync(): string;
181
function isAirplaneMode(): Promise<boolean>;
182
function isAirplaneModeSync(): boolean;
183
```
184
185
[Network and Connectivity](./network-connectivity.md)
186
187
### Hardware Features
188
189
Hardware feature detection and capability checking for cameras, audio devices, input peripherals, and platform-specific hardware. Essential for feature-dependent applications.
190
191
```typescript { .api }
192
function isCameraPresent(): Promise<boolean>;
193
function isCameraPresentSync(): boolean;
194
function isHeadphonesConnected(): Promise<boolean>;
195
function isHeadphonesConnectedSync(): boolean;
196
function hasNotch(): boolean;
197
function hasDynamicIsland(): boolean;
198
function isTablet(): boolean;
199
function isEmulator(): Promise<boolean>;
200
function isEmulatorSync(): boolean;
201
```
202
203
[Hardware Features](./hardware-features.md)
204
205
### React Hooks
206
207
Real-time monitoring hooks for dynamic device states and event-driven updates. Perfect for React components that need to respond to device state changes automatically.
208
209
```typescript { .api }
210
function useBatteryLevel(): number | null;
211
function usePowerState(): Partial<PowerState>;
212
function useDeviceName(): AsyncHookResult<string>;
213
function useIsHeadphonesConnected(): AsyncHookResult<boolean>;
214
function useBrightness(): number | null;
215
216
interface AsyncHookResult<T> {
217
loading: boolean;
218
result: T;
219
}
220
```
221
222
[React Hooks](./react-hooks.md)
223
224
## Types
225
226
```typescript { .api }
227
type DeviceType = 'Handset' | 'Tablet' | 'Tv' | 'Desktop' | 'GamingConsole' | 'unknown';
228
229
type BatteryState = 'unknown' | 'unplugged' | 'charging' | 'full';
230
231
type AvailableCapacityType = 'total' | 'important' | 'opportunistic';
232
233
interface PowerState {
234
batteryLevel: number;
235
batteryState: BatteryState;
236
lowPowerMode: boolean;
237
[key: string]: any;
238
}
239
240
interface LocationProviderInfo {
241
[key: string]: boolean;
242
}
243
244
interface AsyncHookResult<T> {
245
loading: boolean;
246
result: T;
247
}
248
```