react-native-power-saver-detector
v0.1.1
Published
React Native library that provides methods to check and navigate to power-saving mode settings on both Android and iOS platforms.
Downloads
320
Readme
React Native Power Saver Detector
react-native-power-saver-detector
is a React Native library that provides methods for checking Low Power Mode
on iOS and Power Saver/Battery Saver
Mode on Android, as well as navigating to the Power Saver/Battery Saver
Mode settings on Android.
Overview
Installation
To install the library, use either npm or yarn:
npm install react-native-power-saver-detector
# or
yarn add react-native-power-saver-detector
Linking
For React Native 0.60 and above, the library should be automatically linked. For older versions, you will need to link the library manually:
react-native link react-native-power-saver-detector
For iOS, don't forget to run pod install
after linking the library:
cd ios && pod install
API
| Method | Description | Platform |
| ----------------------------- | ---------------------------------------------------------------- | -------- |
| isLowPowerModeEnabled
| Checks if Low Power Mode is enabled on iOS. | iOS |
| isPowerSaverModeEnabledSync
| Synchronously checks if Power Saver Mode is enabled on Android. | Android |
| isPowerSaverModeEnabled
| Asynchronously checks if Power Saver Mode is enabled on Android. | Android |
| openPowerSaverSettings
| Navigates to the Power Saver Mode settings on Android. | Android |
isLowPowerModeEnabled
Checks if Low Power Mode is enabled on iOS.
Returns
Promise<boolean | null>
: A promise that resolves to true
if Low Power Mode is enabled, false
if not, and null
if the check fails. This might return null
if the system information is unavailable or an error occurs during the check.
Example
import { PowerSaverDetector } from 'react-native-power-saver-detector';
PowerSaverDetector.isLowPowerModeEnabled().then((isEnabled) => {
console.log('Low Power Mode enabled:', isEnabled);
});
isPowerSaverModeEnabledSync
Synchronously checks if Power Saver Mode is enabled on Android.
Returns
boolean | null
: Returns true
if Power Saver Mode is enabled, false
if not, and null
if the PowerManager service is unavailable. This might return null
if the PowerManager service is not available on the device or an error occurs during the check.
Example
import { PowerSaverDetector } from 'react-native-power-saver-detector';
const isEnabled = PowerSaverDetector.isPowerSaverModeEnabledSync();
console.log('Power Saver Mode enabled (sync):', isEnabled);
isPowerSaverModeEnabled
Asynchronously checks if Power Saver Mode is enabled on Android.
Returns
Promise<boolean | null>
: A promise that resolves to true
if Power Saver Mode is enabled, false
if not, and null
if the PowerManager service is unavailable. This might return null
if the PowerManager service is not available on the device or an error occurs during the check.
Example
import { PowerSaverDetector } from 'react-native-power-saver-detector';
PowerSaverDetector.isPowerSaverModeEnabled().then((isEnabled) => {
console.log('Power Saver Mode enabled (async):', isEnabled);
});
openPowerSaverSettings
Navigates to the Power Saver Mode settings on Android.
Example
import { PowerSaverDetector } from 'react-native-power-saver-detector';
PowerSaverDetector.openPowerSaverSettings();
Contributing
Contributions are welcome! Please open an issue or submit a pull request to discuss any changes.
License
This project is licensed under the MIT License.