react-native-battery-optimization-android
v0.1.5
Published
Battery optimization settings for react-native, android only
Downloads
26
Maintainers
Readme
react-native-battery-optimization-android
About
react-native disable or evade from Android's doze, standby mode.
Especially, Using Push Notification.
Installation
npm install react-native-battery-optimization-android
yarn add react-native-battery-optimization-android
Permissions
AndroidManifest.xml
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" android:minSdkVersion="29" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" android:minSdkVersion="33" />
Usage
import RnBatteryAndroid from 'react-native-battery-optimization-android';
function App() {
useEffect(() => {
RnBatteryAndroid?.getAppPackageName().then( (e) => console.log('packageName : ', e));
}, []);
const openSettings = () => {
RnBatteryAndroid?.openSettings();
}
const isWhiteListed = async () => {
const result :boolean = await RnBatteryAndroid?.checkIsWhitelisted();
ToastAndroid.show(`IsWhitelisted => ${result}`, ToastAndroid.TOP);
if(!result)
{
try {
RnBatteryAndroid?.checkBattery();
RnBatteryAndroid?.requestIgnoreBatteryOptimizations();
}
catch(e)
{
console.log(e);
}
}
}
return (
<View>...</View>
)
}
APIs
| Name | Return | Desc | |-------------------------------------|-------------------|----------------------| | checkDrawOverlays() | Promise boolean | | | requestDrawOverlays() | Promise boolean | | | checkBatteryOptimizationPermission() | Promise boolean | | | checkIsWhitelisted() | Promise boolean | | | requestIgnoreBatteryOptimizations() | void | | | openSettings() | void | | | checkBattery() | Promise string | Check battery level | | getAppPackageName() | Promise string | Project package Name |
License
Unlicense
We are not responsible for any losses incurred during use.
Made with create-react-native-library