Chinaunix首页 | 论坛 | 博客
  • 博客访问: 360469
  • 博文数量: 79
  • 博客积分: 1270
  • 博客等级: 中尉
  • 技术积分: 1370
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-12 08:48
个人简介

freedom~~~~~~~~~~

文章分类

全部博文(79)

文章存档

2014年(10)

2013年(2)

2012年(13)

2011年(54)

分类: 嵌入式

2011-05-17 10:58:41

  1. package com.android.factorymode;

  2. import android.app.Activity;
  3. import android.content.BroadcastReceiver;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.IntentFilter;
  7. import android.os.BatteryManager;
  8. import android.os.Bundle;
  9. import android.widget.TextView;

  10. public class ChargeTest extends Activity
  11. {
  12.     TextView myText;
  13.     private BroadcastReceiver mbatteryReceiver=new BroadcastReceiver()
  14.     {
  15.         public void onReceive(Context context, Intent intent)
  16.         {
  17.             String action =intent.getAction();
  18.             if(Intent.ACTION_BATTERY_CHANGED.equals(action));
  19.             {
  20.                 int status=intent.getIntExtra("status",BatteryManager.BATTERY_STATUS_UNKNOWN);
  21.                 if(status==BatteryManager.BATTERY_STATUS_CHARGING)
  22.                 {
  23.                     myText.setText(R.string.Charge);
  24.                 }
  25.                 else
  26.                 {
  27.                     myText.setText(R.string.notCharge);
  28.                 }
  29.             }
  30.         }
  31.     };
  32.     /** Called when the activity is first created. */
  33.     @Override
  34.     public void onCreate(Bundle savedInstanceState)
  35.     {
  36.         super.onCreate(savedInstanceState);
  37.         setContentView(R.layout.charge_test);
  38.         myText=(TextView)findViewById(R.id.message);
  39.         
  40.         registerReceiver(mbatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
  41.     }
  42. }
阅读(10345) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~