java - How to get battery level -


i trying battery level of mobile using adf. mean example if battery charged fifty want value.

how can achieve this?

i don't know can achieve using android-intent.

if yes, have do?

here code sample explains how battery information: http://www.tutorialforandroid.com/2009/01/getting-battery-information-on-android.html

to sum up, broadcast receiver action_battery_changed intent set dynamically, because can not received through components declared in manifests, explicitly registering context.registerreceiver().

public class main extends activity {   private textview batterytxt;   private broadcastreceiver mbatinforeceiver = new broadcastreceiver(){     @override     public void onreceive(context ctxt, intent intent) {       int level = intent.getintextra(batterymanager.extra_level, 0);       batterytxt.settext(string.valueof(level) + "%");     }   };    @override   public void oncreate(bundle b) {     super.oncreate(b);     setcontentview(r.layout.main);     contenttxt = (textview) this.findviewbyid(r.id.batterytxt);     this.registerreceiver(this.mbatinforeceiver, new intentfilter(intent.action_battery_changed));   } } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -