Skip to content

Battery doest not work when app in background #21

Description

@Shelestenko

Battery doest not work in android when app in background (minimized).
I have error:

error Error: Battery manager is not active
    at createErrorFromErrorData (E:\projects\project_name\node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:123)
    at E:\projects\project_name\node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:80
    at MessageQueue.__invokeCallback (E:\projects\project_name\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:400)
    at E:\projects\project_name\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:139
    at MessageQueue.__guardSafe (E:\projects\project_name\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:316)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (E:\projects\project_name\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:138)
    at debuggerWorker.js:72

Please fix it.
I use
"react-native": "0.54.4",
"react-native-background-task": "0.2.1"

some code:

file battery
export const getLevel = onLevel => {
  DeviceBattery.getBatteryLevel().then(level => {
    const battery_level = Math.round(level * 100);
    onLevel(battery_level);
  });
}

file in use
import * as Battery from '../battery';

try {
        DeviceBattery.getBatteryLevel().then(level => {
            const battery_l = Math.round(level * 100);
        });
 } catch (e) {
        console.log("error", e);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions