Indonesian English French German Spain Italian Russian Portuguese Japanese Dutch Arabic Chinese Simplified

Intents:Battery Information

Monday, July 19, 2010

 this source code is to read battery state and view it.

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;
public class extends Activity (batteryInformation

private TextView batteryTxt;

         private BroadcastReceiver BroadcastReceiver mBatInfoReceiver = new () (

@ Override

public void onReceive (Context arg0, Intent intent) (

                     / / TODO Auto-generated method stub
int level = intent.getIntExtra ("level", 0); //get the level battery
batteryTxt.setText (String.valueOf (level) + "%");

@ Override

public void OnCreate (Bundle Icicle) (
super.onCreate (Icicle);
setContentView (R.layout.main);
batteryTxt = (TextView) this.findViewById (;
this.registerReceiver (this.mBatInfoReceiver,
New IntentFilter (Intent.ACTION_BATTERY_CHANGED));

Pro Android 2 
Android Application Development: Programming with the Google SDKProfessional Android 2 Application Development (Wrox Programmer to Programmer) 

2 comment:

dfian said...

mantab artikelnya Sob.

learningandroid said...


Post a Comment

Theme by New wp themes | Bloggerized by Dhampire