@dahmaular/react-native-device-info-sdk
v1.0.0
Published
A comprehensive React Native SDK for getting device information including battery status on both Android and iOS
Downloads
10
Maintainers
Readme
React Native Device Info SDK
A comprehensive React Native SDK for getting detailed device information including battery status, system info, hardware details, network information, security status, and display properties on both Android and iOS platforms.
Features
- Battery Information: Level, charging status, health, temperature, voltage
- System Information: OS version, device model, build info, kernel version
- Hardware Information: Memory, storage, sensors, camera info, capabilities
- Network Information: Connection type, WiFi details, cellular info, IP address
- Security Information: Screen lock, root/jailbreak detection, biometric capabilities
- Display Information: Screen dimensions, density, orientation, brightness
- Real-time Monitoring: Battery and network state change events
- Performance Optimized: Caching and background processing
- TypeScript Support: Full type definitions included
Installation
npm install react-native-device-info-sdk
# or
yarn add react-native-device-info-sdkiOS Setup
- Run pod install:
cd ios && pod install- Add the following permissions to your
Info.plistif you want full functionality:
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs location access to determine network information.</string>Android Setup
The following permissions are automatically added to your AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.BATTERY_STATS" />Usage
Basic Usage
import { getDeviceInfo, getBatteryInfo } from 'react-native-device-info-sdk';
// Get all device information
const deviceInfo = await getDeviceInfo();
console.log('Device Info:', deviceInfo);
// Get battery information only
const batteryInfo = await getBatteryInfo();
console.log('Battery Info:', batteryInfo);Battery Information
import { getBatteryInfo, startBatteryMonitoring, stopBatteryMonitoring } from 'react-native-device-info-sdk';
import { DeviceEventEmitter } from 'react-native';
// Get current battery info
const battery = await getBatteryInfo();
console.log('Battery Level:', battery.batteryLevel);
console.log('Is Charging:', battery.isCharging);
console.log('Battery Status:', battery.batteryStatus);
// Start monitoring battery changes
await startBatteryMonitoring();
const batteryListener = DeviceEventEmitter.addListener('BatteryStateChanged', (event) => {
console.log('Battery changed:', event.battery);
});
// Stop monitoring
await stopBatteryMonitoring();
batteryListener.remove();System Information
import { getSystemInfo } from 'react-native-device-info-sdk';
const systemInfo = await getSystemInfo();
console.log('Platform:', systemInfo.platform);
console.log('OS Version:', systemInfo.osVersion);
console.log('Device Model:', systemInfo.deviceModel);
console.log('Device Brand:', systemInfo.deviceBrand);Hardware Information
import { getHardwareInfo, getCameraInfo, getSensorList } from 'react-native-device-info-sdk';
const hardware = await getHardwareInfo();
console.log('Total Memory:', hardware.totalMemory);
console.log('Available Storage:', hardware.availableStorage);
console.log('Has NFC:', hardware.hasNFC);
console.log('Has Fingerprint:', hardware.hasFingerprint);
const cameras = await getCameraInfo();
console.log('Cameras:', cameras);
const sensors = await getSensorList();
console.log('Available Sensors:', sensors);Network Information
import { getNetworkInfo, startNetworkMonitoring } from 'react-native-device-info-sdk';
const network = await getNetworkInfo();
console.log('Connection Type:', network.connectionType);
console.log('Is Connected:', network.isConnected);
console.log('WiFi SSID:', network.wifiSSID);
console.log('IP Address:', network.ipAddress);Security Information
import { getSecurityInfo, checkDeviceIntegrity } from 'react-native-device-info-sdk';
const security = await getSecurityInfo();
console.log('Is Device Secure:', security.isDeviceSecure);
console.log('Has Screen Lock:', security.hasScreenLock);
console.log('Is Jailbroken/Rooted:', security.isJailbroken || security.isRooted);
console.log('Is Emulator:', security.isEmulator);
console.log('Supported Biometrics:', security.supportedBiometrics);
const isIntegrityOk = await checkDeviceIntegrity();
console.log('Device Integrity:', isIntegrityOk);Display Information
import { getDisplayInfo, getBrightness } from 'react-native-device-info-sdk';
const display = await getDisplayInfo();
console.log('Screen Width:', display.screenWidth);
console.log('Screen Height:', display.screenHeight);
console.log('Density:', display.density);
console.log('Orientation:', display.orientation);
console.log('Has Notch:', display.hasNotch);
const brightness = await getBrightness();
console.log('Current Brightness:', brightness);Advanced Usage with Options
import DeviceInfoManager from 'react-native-device-info-sdk';
const manager = DeviceInfoManager.getInstance({
enableBatteryMonitoring: true,
enableNetworkMonitoring: true,
cacheDuration: 30000, // Cache for 30 seconds
includeSystemInfo: true,
includeHardwareInfo: true,
includeNetworkInfo: true,
includeSecurityInfo: true,
includeDisplayInfo: true,
includeBatteryInfo: true,
});
const deviceInfo = await manager.getDeviceInfo();API Reference
Methods
getDeviceInfo(options?: DeviceInfoSDKOptions): Promise<DeviceInfo>
Returns comprehensive device information including all categories.
getBatteryInfo(): Promise<BatteryInfo>
Returns detailed battery information.
getSystemInfo(): Promise<SystemInfo>
Returns system and OS information.
getHardwareInfo(): Promise<HardwareInfo>
Returns hardware specifications and capabilities.
getNetworkInfo(): Promise<NetworkInfo>
Returns network connection information.
getSecurityInfo(): Promise<SecurityInfo>
Returns security-related information.
getDisplayInfo(): Promise<DisplayInfo>
Returns display properties and screen information.
getCameraInfo(): Promise<CameraInfo[]>
Returns information about available cameras.
getSensorList(): Promise<string[]>
Returns list of available sensors.
getBrightness(): Promise<number>
Returns current screen brightness (0-1).
startBatteryMonitoring(): Promise<void>
Starts monitoring battery state changes.
stopBatteryMonitoring(): Promise<void>
Stops monitoring battery state changes.
startNetworkMonitoring(): Promise<void>
Starts monitoring network state changes.
stopNetworkMonitoring(): Promise<void>
Stops monitoring network state changes.
checkDeviceIntegrity(): Promise<boolean>
Checks if the device has been compromised (rooted/jailbroken).
clearCache(): void
Clears the internal cache.
Events
BatteryStateChanged
Emitted when battery state changes (when monitoring is enabled).
DeviceEventEmitter.addListener('BatteryStateChanged', (event) => {
console.log('Battery info:', event.battery);
console.log('Timestamp:', event.timestamp);
});NetworkStateChanged
Emitted when network state changes (when monitoring is enabled).
DeviceEventEmitter.addListener('NetworkStateChanged', (event) => {
console.log('Network info:', event.network);
console.log('Timestamp:', event.timestamp);
});Types
The SDK includes comprehensive TypeScript definitions for all return types:
DeviceInfo- Complete device informationBatteryInfo- Battery status and healthSystemInfo- OS and device informationHardwareInfo- Hardware specificationsNetworkInfo- Network connection detailsSecurityInfo- Security statusDisplayInfo- Screen and display propertiesCameraInfo- Camera specificationsDeviceInfoSDKOptions- Configuration options
Example Response
{
"system": {
"platform": "ios",
"osVersion": "16.4",
"deviceModel": "iPhone14,2",
"deviceBrand": "Apple",
"deviceName": "iPhone 13 Pro"
},
"battery": {
"batteryLevel": 85,
"batteryStatus": "discharging",
"isCharging": false,
"isFull": false,
"isLow": false,
"health": "good",
"technology": "Li-ion"
},
"hardware": {
"totalMemory": 6442450944,
"availableMemory": 2147483648,
"totalStorage": 128849018880,
"hasNFC": true,
"hasFaceID": true,
"cameras": [
{
"id": "0",
"position": "back",
"hasFlash": true
}
]
},
"network": {
"isConnected": true,
"connectionType": "wifi",
"wifiSSID": "\"MyWiFi\"",
"ipAddress": "192.168.1.100"
},
"security": {
"isDeviceSecure": true,
"hasScreenLock": true,
"isJailbroken": false,
"supportedBiometrics": ["face"]
},
"display": {
"screenWidth": 390,
"screenHeight": 844,
"density": 3.0,
"brightness": 0.8,
"orientation": "portrait"
}
}Platform Differences
Some features are platform-specific:
iOS Only
hasTouchID,hasFaceIDisJailbroken- Detailed
utsnameinformation
Android Only
isRooted,hasFingerprintisAdbEnabled,isDeveloperModeEnabled- Detailed build information (
fingerprint,bootloader, etc.) - Battery temperature and voltage
- Detailed cellular information
Performance Considerations
- The SDK uses intelligent caching to avoid repeated native calls
- Heavy operations are performed on background threads
- Network and location-based features require appropriate permissions
- Battery monitoring should be stopped when not needed to preserve battery life
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library
