1、 // 注册广播
ReceiveBroadCast receiveBroadCast = new ReceiveBroadCast();
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.broad");
registerReceiver(receiveBroadCast, filter);
2、//发送广播
Intent intent = new Intent();
intent.putExtra("data","broadcastdemo " );
intent.setAction("android.intent.action.broad");
sendBroadcast(intent); //发送广播 sendOrderedBroadcast(intent, null); //发送有序广播
3、//取消广播
unregisterReceiver(receiveBroadCast);
4、继承BroadcastReceiver类,并实现其onReceive方法,可以接收发送的广播,并实现某个功能,比如以下的广播接收器将接收到的数据用textview控件显示出来。
public class ReceiveBroadCast extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
String message = intent.getStringExtra("data");
tv.setText(message);
}