JSPM

@brandonhenao/react-native-disable-battery-optimizations-android

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 51
  • Score
    100M100P100Q78292F
  • License MIT

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

Package Exports

  • @brandonhenao/react-native-disable-battery-optimizations-android

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@brandonhenao/react-native-disable-battery-optimizations-android) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-native-disable-battery-optimizations-android

The act of requesting REQUEST_IGNORE_BATTERY_OPTIMIZATIONS in the manifest is what may get you banned, so it was remove.

🔥🔥 Upgraded and merged some fixes from other forked repos 🔥🔥

this is a fork of https://github.com/IronTony/react-native-disable-battery-optimizations-android.

Getting started

$ npm i @brandonhenao/react-native-disable-battery-optimizations-android

Mostly automatic installation for react native >= v 0.60

Manual linking not required for above versions

For manual linking : $ react-native link @brandonhenao/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 ':@brandonhenao/react-native-disable-battery-optimizations-android'
    project(':@brandonhenao/react-native-disable-battery-optimizations-android').projectDir = new File(rootProject.projectDir, 	'../node_modules/@brandonhenao/react-native-disable-battery-optimizations-android/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
    compile project(':@brandonhenao/react-native-disable-battery-optimizations-android')

Usage

import RNDisableBatteryOptimizationsAndroid from '@brandonhenao/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();