Code Monkey home page Code Monkey logo

Comments (3)

lid avatar lid commented on June 8, 2024 8

The behavior of isCharging() is a little wonky (as tested on API 25). It appears that even if the battery status is 2 (Charging) and the device is on AC, isCharging will not return true unless the battery level has actually incremented (e.g. via adb shell dumpsys battery set level 50 && adb shell dumpsys battery set level 51). At very least, this should be documented in the lesson notes.

Also, if you fall back to the sticky broadcast intent, this relies instead on the battery charging status set e.g. via adb shell dumpsys battery set status 2.

In any case, the two methods for determining charging status in API >= 23 and API < 23 presented in the lesson are not equivalent. They are also different than checking whether the device is plugged in, i.e. they do not correspond to ACTION_POWER_CONNECTED and ACTION_POWER_DISCONNECTED as is implied in the lesson.

from ud851-exercises.

DigitTeaser avatar DigitTeaser commented on June 8, 2024

In the BatteryManager document, the isCharging() method was described as below.

Return true if the battery is currently considered to be charging. This means that the device is plugged in and is supplying sufficient power that the battery level is going up (or the battery is fully charged).

Therefore, what lid said was right. The isCharging() method only returns true when the battery level has actually incremented. I think the Android Framework team considered the situation that the device was plugged in some insufficient power. It usually happens when the device is charging using a power bank or through a car USB port.

from ud851-exercises.

johnshea avatar johnshea commented on June 8, 2024

Closing this issue as it is not related to the repo's code.

from ud851-exercises.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.