
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);