Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8262743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:51:29+00:00 2026-06-08T03:51:29+00:00

I was reading the guide here about setting up a BroadcastReceiver to check changes

  • 0

I was reading the guide here about setting up a BroadcastReceiver to check changes in the battery. And it stated that I could setup a BroadcastReceiver like this:

<receiver android:name=".PowerConnectionReceiver">
    <intent-filter>
        <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
        <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
    </intent-filter>
</receiver>

in my manifest and this as a class:

public class PowerConnectionReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) { 
        int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
        boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
                        status == BatteryManager.BATTERY_STATUS_FULL;

        int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
        boolean usbCharge = chargePlug == BATTERY_PLUGGED_USB;
        boolean acCharge = chargePlug == BATTERY_PLUGGED_AC;
    }
}

Is the BroadcastReceiver call onReceive(...) ONLY when a CHANGE occurs in the battery state? For example, what if the user had the device plugged into their computer and it was charging the entire time the BroadcastReceiver was running. Would it detect a change, since technically, the device’s battery status didn’t change? Whenever I get isCharging, would it be the current value, or the value at the last change? I want to check if it did change and what it always is so that I can optimize my application and save battery life.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:51:30+00:00Added an answer on June 8, 2026 at 3:51 am

    It will get called only on these actions, as you specified…

    1. android.intent.action.ACTION_POWER_CONNECTED
    2. android.intent.action.ACTION_POWER_DISCONNECTED

    And that’s when…

    1) External power has been connected to the device.

    2) External power has been removed from the device.

    If you need to track battery power changes, you should include this filter in your manifest.

    android.intent.action.ACTION_BATTERY_CHANGED

    Btw.
    isCharging would be the current state, of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For reading local files this guide here uses the following code: function handleFileSelect(evt) {
After reading this paragraph in the CouchDB Definitive Guide ( here ): If you
I am reading an development guide of Facebook Developers at here It says that
I saved my project.apk file, and I was reading this document: http://developer.android.com/guide/publishing/app-signing.html#setup and they
I'm reading Sybex Complete Java 2 Certification Study Guide April 2005 (ISBN0782144195). This book
I'd like to know the best way to go about doing this. I was
When I'm reading the apple iOS Developer Guide, it explains me a bit about
Reading through the Grails docs (see here http://grails.org/doc/latest/guide/theWebLayer.html#ajax ), I was led to believe
I've been reading through Beej's Guide to Network Programming to get a handle on
I have been reading the JavaScript Scripting Guide for Quicktime and in there it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.