WEB开发网
开发学院手机开发Android 开发 Android中电池信息(Battery information)的取得 阅读

Android中电池信息(Battery information)的取得

 2010-09-10 00:41:00 来源:WEB开发网   
核心提示:012public class BatteryTestActivity extends Activity {013 /** Called when the activity is first created. */014 @Override015 public void onCreate(Bundle savedIns

012public class BatteryTestActivity extends Activity {

013 /** Called when the activity is first created. */

014 @Override

015 public void onCreate(Bundle savedInstanceState) {

016 super.onCreate(savedInstanceState);

017 setContentView(R.layout.main);

018 }

019

020 @Override

021 protected void onResume() {

022 super.onResume();

023

024 IntentFilter filter = new IntentFilter();

025

026 filter.addAction(Intent.ACTION_BATTERY_CHANGED);

027 registerReceiver(mBroadcastReceiver, filter);

028 }

029

030 @Override

031 protected void onPause() {

032 super.onPause();

033

034 unregisterReceiver(mBroadcastReceiver);

035 }

036

037 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {

038 @Override

039 public void onReceive(Context context, Intent intent) {

040 String action = intent.getAction();

041 if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {

042 int status = intent.getIntExtra("status", 0);

043 int health = intent.getIntExtra("health", 0);

044 boolean present = intent.getBooleanExtra("present", false);

045 int level = intent.getIntExtra("level", 0);

046 int scale = intent.getIntExtra("scale", 0);

047 int icon_small = intent.getIntExtra("icon-small", 0);

048 int plugged = intent.getIntExtra("plugged", 0);

049 int voltage = intent.getIntExtra("voltage", 0);

050 int temperature = intent.getIntExtra("temperature", 0);

051 String technology = intent.getStringExtra("technology");

052

053 String statusString = "";

054

055 switch (status) {

上一页  1 2 3 4  下一页

Tags:Android 电池 信息

编辑录入:coldstar [复制链接] [打 印]
赞助商链接