Android Display phone charge

Source: Internet
Author: User

Package Com.basillee.asus.demo;import Android.app.notification;import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;import Android.content.intentfilter;import Android.os.batterymanager;import Android.support.v7.app.actionbaractivity;import Android.os.Bundle;import Android.view.menu;import Android.view.menuitem;import Android.view.view;import Android.widget.Button;import    Android.widget.textview;public class MainActivity11 extends Actionbaractivity {private TextView textviewlevel=null;    private int batterylevel;    private int batteryscale;    Private Button buttonbatteryshow; Private Broadcastreceiver broadcastreceiver=new Broadcastreceiver () {@Override public void onreceive (Contex T context, Intent Intent) {//Gets the current charge, if no specific value is obtained, the default is 0 Batterylevel=intent.getintextra (BATTERYMANAGER.E            xtra_level,0); To get the maximum charge, if no specific value is obtained, the default is Batteryscale=intent.getintextra (Batterymanager.extra_SCALE,100);        Displays the Power Textviewlevel.settext ("Charge" + (Batterylevel*100/batteryscale) + "%");    }    };        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.LAYOUT.ACTIVITY_MAIN_ACTIVITY11);        Textviewlevel= (TextView) Findviewbyid (r.id.textviewbattery);        buttonbatteryshow= (Button) Findviewbyid (r.id.button_show_battery);  Buttonbatteryshow.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View                V) {intentfilter intentfilter=new intentfilter (intent.action_battery_changed);            Register the receiver to obtain the Power information Registerreceiver (Broadcastreceiver, Intentfilter);    }        }); }}

http://jingyan.baidu.com/season/48891

Android Display phone charge

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.