Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
react-native-device-battery
Advanced tools
Observe battery state changes in your react native application
Get and observe the devices battery level and charging status
Install the node module
npm install react-native-device-battery --save
TBD
Add the following to android/settings.grade
include ':react-native-device-battery'
project(':react-native-device-battery').projectDir = new File(settingsDir, '../node_modules/react-native-device-battery/android')
Add the following to android/app/build.gradle
compile project(':react-native-device-battery')
Register the module in MainActivity.java
import com.robinpowered.react.battery.DeviceBatteryPackage; // <--- import
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
......
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new DeviceBatteryPackage()) // <------ add this line to yout MainActivity class
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "AndroidRNSample", null);
setContentView(mReactRootView);
}
......
}
import DeviceBattery from 'react-native-device-battery';
// get the battery level
DeviceBattery.getBatteryLevel().then(level => {
console.log(level); // between 0 and 1
});
// check if the device is charging
DeviceBattery.isCharging().then(isCharging => {
console.log(isCharging) // true or false
});
// as a listener
var onBatteryStateChanged = (state) => {
console.log(state) // {level: 0.95, charging: true}
};
// to attach a listener
DeviceBattery.addListener(onBatteryStateChanged);
// to remove a listener
DeviceBattery.removeListener(onBatteryStateChanged);
FAQs
Observe battery state changes in your react native application
We found that react-native-device-battery demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.