爪哇夜未眠:杰哥走向架构之路
itanger
全部博文(215)
DreamWeaver(2)
Div+Css(1)
系统(4)
BIOS(1)
websphere(2)
工具类(1)
android(16)
Lucene(1)
Log4j(1)
Jboss(1)
Java架构(3)
J2ee(2)
SSH(2)
WebService(2)
WML-无线标记语言(2)
WebLogic(3)
iBatis(1)
EJB(3)
Spring(3)
JAVA基础(17)
Eclipse(3)
OSCache(1)
Tomcat(6)
服务器(0)
数据库(3)
Servlet(1)
算法(3)
JBuilder(1)
Hibenate(9)
JSF(7)
Struts(14)
2012年(1)
2011年(24)
2009年(16)
2008年(91)
2007年(83)
asacml
追梦小花
cynthia
浪花小雨
dr282235
alanhe21
pjchen
davelv
limengji
分类: Java
2011-01-12 23:21:12
import android.app.Activity;import android.content.IntentFilter;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;
public class TestBC2Activity extends Activity { /** Called when the activity is first created. */ private Button registerButton = null; private Button unregisterButton = null; private SMSReceiver smsReceiver = null; private static final String SMS_ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); registerButton = (Button)findViewById(R.id.register); registerButton.setOnClickListener(new RegisterReceiverListener()); unregisterButton = (Button)findViewById(R.id.unregister); unregisterButton.setOnClickListener(new UnRegisterReceiverListener()); } class RegisterReceiverListener implements OnClickListener{
@Override public void onClick(View v) { //生成一个BroiadcastReceiver对象 smsReceiver = new SMSReceiver(); //生成一个IntentFilter对象 IntentFilter filter = new IntentFilter(); //为IntentFilter添加一个Action filter.addAction(SMS_ACTION); //将BroadcastReceiver对象注册到系统当中 TestBC2Activity.this.registerReceiver(smsReceiver, filter); } } class UnRegisterReceiverListener implements OnClickListener{
@Override public void onClick(View v) { //解除BroadcastReceiver对象的注册 TestBC2Activity.this.unregisterReceiver(smsReceiver); } }}
上一篇:广播机制入门
下一篇:解析XML
登录 注册