Skip to content

React native library for detecting Power Saving changes and accessing it current state, for Android.

License

Notifications You must be signed in to change notification settings

betaacid/react-native-power-saving-mode

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-power-saving-mode

React native library for detecting Power Saving changes and accessing it current state, for Android.

Getting started

$ npm install react-native-power-saving-mode --save

Mostly automatic installation

$ react-native link react-native-power-saving-mode

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import io.powerSavingMode.RNPowerSavingModePackage; to the imports at the top of the file
  • Add new RNPowerSavingModePackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:

    include ":react-native-power-saving-mode"
    project( ":react-native-power-saving-mode" ).projectDir = new File( 
    	rootProject.projectDir,		
    	"../node_modules/react-native-power-saving-mode/android" 
    )
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:

    • Gradle version < 3 : compile project( ":react-native-power-saving-mode" )
    • Gradle version >= 3 : implementation project( ":react-native-power-saving-mode" )

Usage

import { powerSavingOn, powerSavingModeChanged } from "react-native-power-saving-mode"

async componentDidMount() {

 /* Register Listener for power saving mode changes. */
 powerSavingModeChanged( this.powerSavingChangeHandler )
 
 /* Access the current value. */
 let isOn = await powerSavingOn();
}

powerSavingChangeHandler( isOn ) {
 /* TODO YOUR CODE HERE */
}

About

React native library for detecting Power Saving changes and accessing it current state, for Android.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 82.5%
  • JavaScript 17.5%