Android programming method for detecting the current power status

Source: Internet
Author: User

Android programming method for detecting the current power status

This article describes how to detect the current power status using Android programming. We will share this with you for your reference. The details are as follows:

The current power status is detected:

IntentFilter mIntentFilter = new IntentFilter ();

MIntentFilter. addAction (Intent. ACTION_BATTERY_CHANGED );

RegisterReceiver (mIntentReceiver, mIntentFilter );

// Declare the Message Processing Process

Private BroadcastReceiver mIntentReceiver = new BroadcastReceiver (){

@ Override

Public void onReceive (Context context, Intent intent ){

String action = intent. getAction ();

// Check whether the message is the one we want to process.

If (action. equals (Intent. ACTION_BATTERY_CHANGED )){

// Battery power, number

Log. d ("Battery", "" + intent. getIntExtra ("level", 0 ));

// Maximum battery capacity

Log. d ("Battery", "" + intent. getIntExtra ("scale", 0 ));

// Batteries

Log. d ("Battery", "" + intent. getIntExtra ("voltage", 0 ));

// Battery temperature

Log. d ("Battery", "" + intent. getIntExtra ("temperature", 0 ));

// Battery status. A number is returned.

// BatteryManager. BATTERY_STATUS_CHARGING indicates the charging status.

// BatteryManager. BATTERY_STATUS_DISCHARGING under discharge

// BatteryManager. BATTERY_STATUS_NOT_CHARGING is not charged

// BatteryManager. BATTERY_STATUS_FULL battery is full

Log. d ("Battery", "" + intent. getIntExtra ("status", BatteryManager. BATTERY_STATUS_UNKNOWN ));

// BatteryManager. BATTERY_PLUGGED_AC indicates the charger, not the value, indicating the USB

Log. d ("Battery", "" + intent. getIntExtra ("plugged", 0 ));

// Battery health condition. A number is returned.

// BatteryManager. BATTERY_HEALTH_GOOD

// BatteryManager. BATTERY_HEALTH_OVERHEAT is overheated.

// BatteryManager. BATTERY_HEALTH_DEAD no electricity

// BatteryManager. BATTERY_HEALTH_OVER_VOLTAGE overvoltage

// BatteryManager. BATTERY_HEALTH_UNSPECIFIED_FAILURE unknown error

Log. d ("Battery", "" + intent. getIntExtra ("health", BatteryManager. BATTERY_HEALTH_UNKNOWN ));

}

}

};

I hope this article will help you with Android program design.

Related Article

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: info-contact@alibabacloud.com 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.