this source code is to read battery state and view it.
import android.app.Activity;
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 (R.id.TextView01);
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:
mantab artikelnya Sob.
thx...
Post a Comment