English subtitles

← Modify WaitForPowerActivity

Get Embed Code
13 Languages

Showing Revision 4 created 05/25/2016 by Udacity Robot.

  1. All right, well done.
  2. Now let's hop back
    into Android Studio and
  3. take a look at the solution for
    this quiz.
  4. All right, first,
    let's look at our applyFilter method.
  5. See the instructor notes for
    the code snippet, specifically.
  6. Now here, we call checkForPower and
  7. if it returns that the phone is not
    charging, we then change the text to
  8. inform the user to plug in their phone
    and return before completing the method.
  9. Simple enough.
  10. All right, let's take a look at
    the logic within checkForPower.
  11. Again, see the instructor notes for
    the code snippet.
  12. Okay, so
    here we are within checkForPower.
  13. Now the first thing we do is we set
    an intent filter to describe for
  14. changes to the battery state.
  15. And then we actually get an integer,
    right here,
  16. representing the battery
    plugged in status.
  17. We then compare this
  18. integer to various constants
    within the BatteryManager class.
  19. For instance, one for whether it's
    charging via AC or alternating current.
  20. This means it's plugged into the wall.
  21. Another for USB.
  22. And finally,
    whether it's charging via wireless.
  23. We wrap the wireless check in an if
    statement to make sure that the SDK
  24. build version is high enough.
  25. And then finally, if it was charging via
    USB, AC, or wireless, we return true.
  26. Otherwise, false.