<intent-filter>
<action
android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
public void onClick(View v)
{
Intent intent=new
Intent();
intent.setAction(ACTION);
sendBroadcast(intent);
}
在程序中注册,而不在xml配置文件中注册:
protected static final String ACTION = "com.szy.broadcast.ACTION";
private SecondReceiver receiver;
//发送消息
public void onClick(View v)
{
Intent intent=new
Intent();
intent.setAction(ACTION);
sendBroadcast(intent);
}
//注册广播
public void onClick(View v)
{
receiver=new
SecondReceiver();
IntentFilter filter=new
IntentFilter();
filter.addAction(ACTION);
registerReceiver(receiver,
filter);
}
//注销广播
public void onClick(View
v)
{
unregisterReceiver(receiver);
}
13 BroadcastReceiver,码迷,mamicode.com
原文地址:http://www.cnblogs.com/cliffhuang/p/3698489.html