Android Studio源码:
package com.ic.ouridrtest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.reader.ouridr;//引入我们的读卡器类
public class MainActivity extends AppCompatActivity {
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Example of a call to a native method
tv = findViewById(R.id.sample_text);
tv.setText("操作结果");
}
//读卡------------------------------------------------------------------------------------------
public void idr_read(View view)
{
byte status;//存放返回值
byte[] idserial = new byte[5];
String strls = "";
status = ouridr.read(this,idserial);
if(status == 0)
{
strls = "读取成功!卡号为";
String strls1 = "0"+Integer.toHexString(idserial[0]);
strls = strls + strls1.substring(strls1.length()-2) +"-";
strls1 = "0"+Integer.toHexString(idserial[1]);
strls = strls + strls1.substring(strls1.length()-2) +"-";
strls1 = "0"+Integer.toHexString(idserial[2]);
strls = strls + strls1.substring(strls1.length()-2) +"-";
strls1 = "0"+Integer.toHexString(idserial[3]);
strls = strls + strls1.substring(strls1.length()-2) +"-";
strls1 = "0"+Integer.toHexString(idserial[4]);
strls = strls + strls1.substring(strls1.length()-2);
}
else
{
if(status == 8)
{
strls = "请将卡放在ID卡读卡器感应区";
}
else if(status == 23)
{
strls = "错误提示:读卡器未插入";
}
else
{
strls = "错误代码:" + Integer.toString(status);
}
}
tv.setText(strls);
}
//仅读一次,重新取放卡才能读到第二次---------------------------------------------------------------
public void idr_read_once(View view)
{
byte status;//存放返回值
byte[] idserial = new byte[5];
String strls = "";
status = ouridr.readonce(this,idserial);
if(status == 0)
{
strls = "读取成功!卡号为";
String strls1 = "0"+Integer.toHexString(idserial[0]);
strls = strls + strls1.substring(strls1.length()-2) +"-";
strls1 = "0"+Integer.toHexString(idserial[1]);
strls = strls + strls1.substring(strls1.length()-2) +"-";
strls1 = "0"+Integer.toHexString(idserial[2]);
strls = strls + strls1.substring(strls1.length()-2) +"-";
strls1 = "0"+Integer.toHexString(idserial[3]);
strls = strls + strls1.substring(strls1.length()-2) +"-";
strls1 = "0"+Integer.toHexString(idserial[4]);
strls = strls + strls1.substring(strls1.length()-2);
}
else
{
if(status == 8)
{
strls = "请将卡放在ID卡读卡器感应区";
}
else if(status == 23)
{
strls = "错误提示:读卡器未插入";
}
else
{
strls = "错误代码:" + Integer.toString(status);
}
}
tv.setText(strls);
}
//读出设备全球唯一的设备编号,作为加密狗用----------------------------------------------------------
public void pcdgetdevicenumber(View view)
{
byte status;//存放返回值
byte[] devicenumber = new byte[4];
String strls = "";
status = ouridr.pcdgetdevicenumber(this,devicenumber);
if(status == 0)
{
strls = "读取成功!设备编号为";
String strls1 = "0"+Integer.toHexString(devicenumber[0]);
strls = strls + strls1.substring(strls1.length()-2) +"-";
strls1 = "0"+Integer.toHexString(devicenumber[1]);
strls = strls + strls1.substring(strls1.length()-2) +"-";
strls1 = "0"+Integer.toHexString(devicenumber[2]);
strls = strls + strls1.substring(strls1.length()-2) +"-";
strls1 = "0"+Integer.toHexString(devicenumber[3]);
strls = strls + strls1.substring(strls1.length()-2);
}
else
{
if(status == 23)
{
strls = "错误提示:读卡器未插入";
}
else
{
strls = "错误代码:" + Integer.toString(status);
}
}
tv.setText(strls);
}
//让设备发出声响----------------------------------------------------------------------------------
public void idr_beep(View view)
{
byte status;//存放返回值
String strls = "";
status = ouridr.beep(this,50);
if(status == 0)
{
strls = "读卡器嘀一声成功!!!";
}
else
{
if(status == 23)
{
strls = "错误提示:读卡器未插入";
}
else
{
strls = "错误代码:" + Integer.toString(status);
}
}
tv.setText(strls);
}
}