友我科技IC卡读卡器Android开发应用实例


此实例将手动点击按钮读写IC卡的内容。

读写IC卡内容

代码如下:

public class M1 extends Activity
{
private RadioButton rbKeyA;
private TextView txtCardNo;
private EditText edtKey;
private EditText edtBlockID;
private EditText edtData;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_m1);

rbKeyA=(RadioButton) findViewById(R.id.rbkeya);
txtCardNo = (TextView) findViewById(R.id.txtcardno);
edtKey = (EditText) findViewById(R.id.edtkey);
edtKey.setText("FFFFFFFFFFFF");
edtBlockID = (EditText) findViewById(R.id.edtblock);
edtBlockID.setText("1");
edtData = (EditText) findViewById(R.id.edtdata);
edtData.setText("11111111111111112222222222222222");

Button button = (Button) findViewById(R.id.btnreadCard);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
txtCardNo.setText("");
edtData.setText("");

int BlockID = MainActivity.ValidInt( edtBlockID.getText().toString() , 63);
if(BlockID<0)
{
MainActivity.dialog("块号必须是0-63",M1.this);
return;
}

if(!MainActivity.ValidHexString(edtKey.getText().toString(), 6))
{
MainActivity.dialog("密钥必须是6字节16进制",M1.this);
return;
}
if( MainActivity.rfidreader.ISO14443A.YW_RequestCard(MainActivity.rfidreader.ISO14443A.REQUESTMODE_ALL)<0)return;

byte[] CardNo=MainActivity.rfidreader.ISO14443A.YW_AntiCollideAndSelect(MainActivity.rfidreader.ISO14443A.MULTIMODE_ONE);

if(CardNo==null)return;
txtCardNo.setText("卡号:" + MainActivity.bytesToHexString(CardNo));

byte KeyMode=MainActivity.rfidreader.ISO14443A.Key_B;
if(rbKeyA.isChecked())KeyMode=MainActivity.rfidreader.ISO14443A.Key_A; if(MainActivity.rfidreader.ISO14443A.YW_KeyAuthorization(KeyMode, BlockID, MainActivity.HexStringtoBytes( edtKey.getText().toString()))<0)
{
MainActivity.dialog("密钥认证错误",M1.this);
return;
}

byte[] Data = MainActivity.rfidreader.ISO14443A.YW_ReadaBlock(BlockID);
if(Data==null)
{
MainActivity.dialog("读取块失败",M1.this);
return;
}

edtData.setText(MainActivity.bytesToHexString(Data));
MainActivity.rfidreader.ReaderHardware.YW_Buzzer(5, 5, 1);
}
});

Button button2 = (Button) findViewById(R.id.btnwritedata);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
txtCardNo.setText("");


int BlockID = MainActivity.ValidInt( edtBlockID.getText().toString() , 63);
if(BlockID<0)
{
MainActivity.dialog("块号必须是0-63",M1.this);
return;
}

if(!MainActivity.ValidHexString(edtKey.getText().toString(), 6))
{
MainActivity.dialog("密钥必须是6字节16进制",M1.this);
return;
}

if(!MainActivity.ValidHexString(edtData.getText().toString(), 16))
{
MainActivity.dialog("数据必须是16字节16进制",M1.this);
return;
}

if( MainActivity.rfidreader.ISO14443A.YW_RequestCard(MainActivity.rfidreader.ISO14443A.REQUESTMODE_ALL)<0)return;

byte[] CardNo=MainActivity.rfidreader.ISO14443A.YW_AntiCollideAndSelect(MainActivity.rfidreader.ISO14443A.MULTIMODE_ONE);

if(CardNo==null)return;
txtCardNo.setText("卡号:" + MainActivity.bytesToHexString(CardNo));

byte KeyMode=MainActivity.rfidreader.ISO14443A.Key_B;
if(rbKeyA.isChecked())KeyMode=MainActivity.rfidreader.ISO14443A.Key_A; if(MainActivity.rfidreader.ISO14443A.YW_KeyAuthorization(KeyMode, BlockID, MainActivity.HexStringtoBytes( edtKey.getText().toString()))<0)
{
MainActivity.dialog("密钥认证错误",M1.this);
return;
}

byte[] Data = MainActivity.HexStringtoBytes(edtData.getText().toString());

if(MainActivity.rfidreader.ISO14443A.YW_WriteaBlock(BlockID, Data)>0)
{
MainActivity.dialog("数据写入成功",M1.this);
MainActivity.rfidreader.ReaderHardware.YW_Buzzer(5, 5, 1);
}
else
MainActivity.dialog("数据写入失败",M1.this);
}
});
}
}

RFID读写器,SDK,IC卡读卡器,开发包,二次开发,智能卡读卡器,RFID读卡器,CPU卡读写器,读卡模块
北京友我科技有限公司 版权所有 (C)2015-2015
客户服务中心信箱:coodor#126.com(将#改为@).客户服务MSN: coodor#126.com(将#改为@)
热线直拨: 010-57049038 18910685939 QQ: 896163157,1403463073
京ICP备14016005号
微信扫一扫联系我们

微信扫一扫联系我们

友我科技


1
RFID读写器产品手册下载
2
读写器开发SDK下载
3
WEB读卡器开发指南
4
Windows读卡器开发指南
5
Android读卡器开发指南
6
Wince读卡器开发指南
7
PLC读卡器开发指南
8
Linux读卡器开发指南
9
单片机读卡器开发指南
10
PCSC读卡器开发指南