1. 静态广播
见网址: http://www.devdiv.com/forum.php?mod=viewthread&tid=48614
2.同时多个动态广播
private BroadcastReceiver RFIDFinishReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("rfid_card_found"))
{
byte[] uid = new byte[128];
if(RFIDService.ReadUID(uid))
{
String str = String.format("UID:%02X%02X%02X%02X%02X%02X%02X%02X",uid[2],uid[3],uid[4],uid[5],uid[6],uid[7],uid[8],uid[9]);
Toast.makeText(context, str,Toast.LENGTH_SHORT).show();
Log.d("zicox",str);
}
Log.d("zicox","asdfasdfdsfdsf");
RFIDService.PowerOFF();
}
else if(intent.getAction().equals("rfid_card_cancel"))
{
//read failed 广播处理
Log.d("zicox", "in RFID cancel receiver");
}
}
};
//注册广播
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rfid_demo);
//接收广播
//filter.addAction("rfid_card_cancel");
IntentFilter filter= new IntentFilter();
filter.addAction("rfid_card_found");
filter.addAction("rfid_card_cancel");
registerReceiver(RFIDFinishReceiver , filter);
}