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

  • SEARCH
  • Home
  • 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 7397895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:48:17+00:00 2026-05-29T03:48:17+00:00

is there a way or how to get or to know the life span

  • 0

is there a way or how to get or to know the life span of the battery? I’m making a Battery Information just like in the “Battery Doctor Saver Pro” the difference is that the life span that i need. i don’t have any idea on how to do it. can anyone help me with this? THANKS for your help. 🙂 so far this is my code without the “Life Span” that i said.

private BroadcastReceiver battery_receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            boolean isPresent = intent.getBooleanExtra("present", false);
            String technology = intent.getStringExtra("technology");
            int plugged = intent.getIntExtra("plugged", -1);
            int scale = intent.getIntExtra("scale", -1);
            int health = intent.getIntExtra("health", 0);
            int status = intent.getIntExtra("status", 0);
            int rawlevel = intent.getIntExtra("level", -1);
            int level = 0;

            Bundle bundle = intent.getExtras();

            Log.i("BatteryLevel", bundle.toString());

            if (isPresent) {
                if (rawlevel >= 0 && scale > 0) {
                    level = (rawlevel * 100) / scale;
                }

                String info = "Battery Level: " + level + "%\n";

                info += ("Technology: " + technology + "\n");
                info += ("Plugged: " + getPlugTypeString(plugged) + "\n");
                info += ("Health: " + getHealthString(health) + "\n");
                info += ("Status: " + getStatusString(status) + "\n");

                setBatteryLevelText(info + "\n\n" + bundle.toString());
            } else {
                setBatteryLevelText("Battery not present!!!");
            }
        }
    };

    private String getPlugTypeString(int plugged) {
        String plugType = "Unknown";

        switch (plugged) {
        case BatteryManager.BATTERY_PLUGGED_AC:
            plugType = "AC";
            break;
        case BatteryManager.BATTERY_PLUGGED_USB:
            plugType = "USB";
            break;
        }

        return plugType;
    }

    private String getHealthString(int health) {
        String healthString = "Unknown";

        switch (health) {
        case BatteryManager.BATTERY_HEALTH_DEAD:
            healthString = "Dead";
            break;
        case BatteryManager.BATTERY_HEALTH_GOOD:
            healthString = "Good Condition";
            break;
        case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
            healthString = "Over Voltage";
            break;
        case BatteryManager.BATTERY_HEALTH_OVERHEAT:
            healthString = "Over Heat";
            break;
        case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
            healthString = "Failure";
            break;
        }

        return healthString;
    }

    private String getStatusString(int status) {
        String statusString = "Unknown";

        switch (status) {
        case BatteryManager.BATTERY_STATUS_CHARGING:
            statusString = "Charging";
            break;
        case BatteryManager.BATTERY_STATUS_DISCHARGING:
            statusString = "Discharging";
            break;
        case BatteryManager.BATTERY_STATUS_FULL:
            statusString = "Full";
            break;
        case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
            statusString = "Not Charging";
            break;
        }

        return statusString;
    }
  • 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-05-29T03:48:18+00:00Added an answer on May 29, 2026 at 3:48 am

    Not exactly sure what you are trying to do here, to calculate watt hours or amp hours check this Link:
    http://www.powerstream.com/battery-capacity-calculations.htm
    If you want the time left on the battery you are currently using you need to get the current battery level and then know how fast it is being drained, either by checking how fast it has been drained up until then and then making an assumption or by knowing how much current you will draw.

    Best results will be achieved if you calibrate your code for the exact battery you are using

    (looks like i got beaten to the answer 😉 )

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

Sidebar

Related Questions

Is there a way to get PHP-like print_r(object) funcionality in iPython? I know I
i would like to know if there is a way to get the progId
I would like to know if there's a way to monitor the life of
Is there a way to get individual ant tasks to run quietly? I know
Is there any way to get RoleId without get directly from DB?, I know
Is there a way to programatically get all the android system wallpapers? I know
As far as I know, there's no way to get url hash in a
is there way how to get name ov event from Lambda expression like with
Is there a way to get the exact Headers sent by function like file_get_contents()
Is there any way to get/know the stored Bluetooth link key from my iPhone

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.