Repository navigation
Android System Status
This module is designated to provide information about device status, like battery and Connection status.
if you need information that is not present here try: This Module
You will need to import the module from the library.
import { AndroidSystemStatus } from 'react-native-androide'Note: All the functions of this module are async and return Promises. So you can use await to see de results or use .then().
Some informations about the Android system is fixed, or at least does not change frequently. Information like this has been wrapped in constants described below.
AndroidSystemStatus.brand // "Samsung" for example
AndroidSystemStatus.deviceCountry // "US" for example
AndroidSystemStatus.systemVersion // "8.1.0" for example
AndroidSystemStatus.isEmulator // true if the application is running in a emulator Android
AndroidSystemStatus.apiLevel // 27 for example
AndroidSystemStatus.model // "SM-J7008" for example, if the device is a Samsung J7 // Note: this Promise will never reject
let lang = await AndroidSystemStatus.getCurrentLanguage();
// OR
AndroidSystemStatus.getCurrentLanguage().then(lang => {/* do something with the lang */});Some examples of languages returned: pt-BR, pt-PT, en-US...
This function returns a Promise which, when it resolves, gives the number of free bytes in the disk. The Promise will reject if it's not possible to get this info for some reason. See more about it in the Documentations of Android system.
Take care, the free disk space changes frequently
try {
let nBytes = await AndroidSystemStatus.getFreeDiskStorage();
/* Do Something */
} catch(error) {
/* Work Around */
}
// OR
AndroidSystemStatus.getFreeDiskStorage()
.then(nBytes => {
/* Do Something */
}
).catch(error => {
/* Work Around */
});You can see how much charge the battery have:
let level = await AndroidSystemStatus.getBatteryLevel();
// OR
let level = 0;
AndroidSystemStatus.getBatteryLevel().then(result => level = result);On both situations the var level receives a int value on range 0 to 100 that represent how much the battery is charged in percent.
Get if battery is charging or not:
if(await AndroidSystemStatus.batteryIsCharging()) {
alert('Battery is charging right now');
} else {
alert('Battery is not charging :(');
}
// OR
AndroidSystemStatus.batteryIsCharging().then(result => {
if(result) {
alert('Battery is charging right now');
} else {
alert('Battery is not charging :(');
}
});When resolved, the promise give you a boolean that represents if the battery is charging.
This functions give you a few informations about the status of Wi-Fi and network.
Important note: This functions require a special permission: android.permission.ACCESS_WIFI_STATE. To grant the required permission, add this line: <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> to the Manifest File located in android\app\src\main\AndroidManifest.xml. If this permission are not guaranteed all promises will be rejected.
try {
/*
Get the ip address of the device on local network
Only local ip is returned, for example: 192.168.10.2
Note: The Promise will be rejected if the wifi are not connected,
use AndroidSystemStatus.isWifiConnected() to check before
*/
let ipAddress = await AndroidSystemStatus.getIpAddress();
// Returns the mac address of the device in a string
let macAddress = await AndroidSystemStatus.getMacAddress();
// Returns if(true or false) the user has been activated the Wi-Fi
let isEnabled = await AndroidSystemStatus.isWifiEnabled();
// Returns if(true or false) the Device has been connected on some Router
let isConnected = await AndroidSystemStatus.isWifiConnected();
} catch(error) {
// Possibly access denied because android.permission.ACCESS_WIFI_STATE is not present.
}The function AndroidSystemStatus.getLastKnownLocation() give you the latitude and longitude of the device. The location returned is the last known location of the device.
Important note: This functions require a special permission: android.permission.ACCESS_FINE_LOCATION or android.permission.ACCESS_COARSE_LOCATION.
To grant the required permission, add this line:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
or
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
to the Manifest File located in android\app\src\main\AndroidManifest.xml. If this permission is not guaranteed all promises will be rejected.
getLocation = async () => {
try {
const result = await AndroidSystemStatus.requestFineLocationPermission(); // or requestCoarseLocationPermission()
if (result) {
const location = await AndroidSystemStatus.getLastKnownLocation();
console.log(location);
/*
{
latitude: 33.7785656,
longitude: -84.4217025
}
*/
}
} catch(error) {
// Possibly access denied because android.permission.ACCESS_WIFI_STATE is not present.
}
};