Do not register broadcast, get power information, not necessarily accurate ~

Source: Internet
Author: User

On the Android platform, You need to register a broadcast to obtain the power information. But how can you not register a broadcast?


Private intentfilter mintentfilter = new intentfilter (intent. action_battery_changed); intent = registerreceiver (null, mintentfilter); If (intent! = NULL) {int level = intent. getintextra (Android. OS. batterymanager. extra_level, 0); Boolean ispluggged = intent. getintextra (Android. OS. batterymanager. extra_plugged,-1)> 0 ;}

For specific reasons, refer to API explanation:

The system may broadcast intents that are "Sticky" -- these stay around after the broadcast as finished, to be sent to any later registrations. if your intentfilter matches one of these sticky intents, that intent will be returned by this function
AndSent to yourCyclerAs if it had just been broadcast.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.