rnd

react-native-disable-battery-optimizations-android

A react native library for checking battery optimization and whitelisting in Android

Showing:

Popularity

Downloads/wk

265

GitHub Stars

21

Maintenance

Last Commit

1yr ago

Contributors

2

Package

Dependencies

0

Size (min+gzip)

0.2KB

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

react-native-disable-battery-optimizations-android

Getting started

$ npm install react-native-disable-battery-optimizations-android --save

Mostly automatic installation for react native >= v 0.60

Manual linking not required for above versions

For manual linking : $ react-native link react-native-disable-battery-optimizations-android

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.reactlibrary.RNDisableBatteryOptimizationsandroidPackage; to the imports at the top of the file
  • Add new RNDisableBatteryOptimizationsPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-disable-battery-optimizations-android'
    project(':react-native-disable-battery-optimizations-android').projectDir = new File(rootProject.projectDir,    '../node_modules/react-native-disable-battery-optimizations-android/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-disable-battery-optimizations-android')
    

Usage

import RNDisableBatteryOptimizationsAndroid from 'react-native-disable-battery-optimizations-android';

RNDisableBatteryOptimizationsAndroid.isBatteryOptimizationEnabled().then((isEnabled)=>{
    if(isEnabled){
        RNDisableBatteryOptimizationsAndroid.openBatteryModal();
    }
});

// for direct whitelisting app with Instant Dialogue 
//The user will be taken to a screen where they can indicate that they are willing to suspend portions of Doze mode effects on your app.
Note: Play store will not allow using this method, and will allow only as an exception


RNDisableBatteryOptimizationsAndroid.enableBackgroundServicesDialogue();

Also 
Add  this permission in your AndroidManifest.xml

<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>


Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100