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 8928089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:21:33+00:00 2026-06-15T08:21:33+00:00

I am trying to get the battery change after a certain code. I am

  • 0

I am trying to get the battery change after a certain code. I am using the following code but unfortunately with no luck. I am getting zeros any ideas please

on the on create a:

batteryIntent = registerReceiver(null,new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

private double batteryLevel() {
   int rawlevel = batteryIntent.getIntExtra("level", -1);
   double scale = batteryIntent.getIntExtra("scale", -1);
   double level = -1;
   if (rawlevel >= 0 && scale > 0) {
       level = rawlevel / scale;

   }
return level;

 } 

and on the onClick:

double startbatterylevel = batteryLevel();

//certain code

double estimatedbattery  =  startbatterylevel -  endbatterylevel ;
Estbatterylevel.setText("estimated battery"+estimatedbattery);
  • 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-15T08:21:34+00:00Added an answer on June 15, 2026 at 8:21 am

    as you wrote it, we don’t know if the problem is in the battery level detection method or in the subtraction. What is the output of the batteryLevel(); method? Is it accurate or always a default value?

    You can try to adapt the example on this page: http://mobiledevtuts.com/android/android-sdk-get-device-battery-information/

    public void onCreate(Bundle savedInstanceState) {
        ...
        this.registerReceiver(this.batteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        ...
    }
    
    private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
            Estbatterylevel.setText("estimated battery" + level);
        }
    };
    

    If it is still showing 0, maybe there are compatibility issues. Can you provide your device specifications and android version ?

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

Sidebar

Related Questions

I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I'm trying get some licensing code from AndroidPit.com working, but I get Unable to
I am trying get the data from my database but i am not getting
I am trying get the Regex right for the following scenario but have some
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
I am trying get Struts 2 and Tiles to work and I am using
Trying to get a wildcard search to pick up on any text in org_name
Hello I am trying to get status of battery of the device programmatically. So
When trying get in memcache client, getting the below excepton. Caused by: java.io.IOException: com.fet.myclass.webservice.data.DataList

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.