封装NFC读卡器模式接口
package com.zchr.nfcdemo;
import com.zchr.nfc.ISO7816;
import com.zchr.nfc.NfcBaseActivity;
import com.zchr.nfc.NfcReader;
import com.zchr.util.MyUtil;
import com.zchr.util.SysException;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
public class MainActivity extends NfcBaseActivity {
public TextView m_textViewShow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
m_textViewShow = (TextView) findViewById(R.id.test_show);
//初始化NFC接口
InitNfcInterface(this);
}
//IC卡处理
public void IccProc() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Message message;
ISO7816 iso7816ApduRsp = new ISO7816();
try {
if (NfcReader.ConnectCard() != NfcReader.CARD_READER_SUCCESS) {
throw new SysException("连接卡失败");
}
if (NfcReader.SendApdu("00A404000E315041592E5359532E4444463031", iso7816ApduRsp) != NfcReader.CARD_READER_SUCCESS) {
throw new SysException("发送选择PSE命令失败");
}
message = null;
message = new Message();
message.what = 0;
message.obj = MyUtil.ByteArrayToHexString(iso7816ApduRsp.getByteRspData()) "[" MyUtil.ByteArrayToHexString(iso7816ApduRsp.getSW()) "]";
mHandler.sendMessage(message);
} catch (SysException e) {
message = null;
message = new Message();
message.obj = e.toString();
message.what = 1;
mHandler.sendMessage(message);
} catch (Exception e) {
e.printStackTrace();
message = null;
message = new Message();
message.obj = "发生异常";
message.what = 1;
mHandler.sendMessage(message);
} finally {
}
}
});
thread.start();
}
public Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
m_textViewShow.setText((String) msg.obj);
m_textViewShow.invalidate();
break;
case 1:
m_textViewShow.setText((String) msg.obj);
m_textViewShow.invalidate();
break;
default:
break;
}
super.handleMessage(msg);
}
};
//NFC读写处理
public void NfcReadWriteProc() {
//IC卡处理
IccProc();
}
}
资源文件列表
AdNfcDemo/.classpath , 475
AdNfcDemo/.project , 845
AdNfcDemo/.settings/org.eclipse.jdt.core.prefs , 177
AdNfcDemo/AndroidManifest.xml , 3182
AdNfcDemo/bin/AdNfcDemo.apk , 518821
AdNfcDemo/bin/AndroidManifest.xml , 3182
AdNfcDemo/bin/classes/com/zchr/nfc/ISO7816.class , 2409
AdNfcDemo/bin/classes/com/zchr/nfc/NfcBaseActivity$1.class , 835
AdNfcDemo/bin/classes/com/zchr/nfc/NfcBaseActivity.class , 4145
AdNfcDemo/bin/classes/com/zchr/nfc/NfcReader.class , 3581
AdNfcDemo/bin/classes/com/zchr/nfcdemo/BuildConfig.class , 341
AdNfcDemo/bin/classes/com/zchr/nfcdemo/MainActivity$1.class , 1063
AdNfcDemo/bin/classes/com/zchr/nfcdemo/MainActivity$2.class , 2144
AdNfcDemo/bin/classes/com/zchr/nfcdemo/MainActivity.class , 1297
AdNfcDemo/bin/classes/com/zchr/nfcdemo/R$attr.class , 334
AdNfcDemo/bin/classes/com/zchr/nfcdemo/R$dimen.class , 455
AdNfcDemo/bin/classes/com/zchr/nfcdemo/R$drawable.class , 401
AdNfcDemo/bin/classes/com/zchr/nfcdemo/R$id.class , 420
AdNfcDemo/bin/classes/com/zchr/nfcdemo/R$layout.class , 397
AdNfcDemo/bin/classes/com/zchr/nfcdemo/R$menu.class , 382
AdNfcDemo/bin/classes/com/zchr/nfcdemo/R$string.class , 466
AdNfcDemo/bin/classes/com/zchr/nfcdemo/R$style.class , 425
AdNfcDemo/bin/classes/com/zchr/nfcdemo/R.class , 653
AdNfcDemo/bin/classes/com/zchr/util/MyUtil.class , 1117
AdNfcDemo/bin/classes/com/zchr/util/SysException.class , 521
AdNfcDemo/bin/classes.dex , 1435232
AdNfcDemo/bin/dexedLibs/android-support-v4-e56a3c4257837cd9e67b99b2f0821148.jar , 472014
AdNfcDemo/bin/jarlist.cache , 120
AdNfcDemo/bin/res/crunch/drawable-hdpi/ic_launcher.png , 5964
AdNfcDemo/bin/res/crunch/drawable-mdpi/ic_launcher.png , 3112
AdNfcDemo/bin/res/crunch/drawable-xhdpi/ic_launcher.png , 9355
AdNfcDemo/bin/res/crunch/drawable-xxhdpi/ic_launcher.png , 17889
AdNfcDemo/bin/resources.ap_ , 42108
AdNfcDemo/gen/com/zchr/nfcdemo/BuildConfig.java , 158
AdNfcDemo/gen/com/zchr/nfcdemo/R.java , 2652
AdNfcDemo/ic_launcher-web.png , 51394
AdNfcDemo/libs/android-support-v4.jar , 1422188
AdNfcDemo/proguard-project.txt , 781
AdNfcDemo/project.properties , 563
AdNfcDemo/res/drawable-hdpi/ic_launcher.png , 7658
AdNfcDemo/res/drawable-mdpi/ic_launcher.png , 3777
AdNfcDemo/res/drawable-xhdpi/ic_launcher.png , 12516
AdNfcDemo/res/drawable-xxhdpi/ic_launcher.png , 24777
AdNfcDemo/res/layout/activity_main.xml , 719
AdNfcDemo/res/menu/main.xml , 366
AdNfcDemo/res/values/dimens.xml , 220
AdNfcDemo/res/values/strings.xml , 226
AdNfcDemo/res/values/styles.xml , 697
AdNfcDemo/res/values-v11/styles.xml , 334
AdNfcDemo/res/values-v14/styles.xml , 391
AdNfcDemo/res/values-w820dp/dimens.xml , 381
AdNfcDemo/src/com/zchr/nfc/ISO7816.java , 2496
AdNfcDemo/src/com/zchr/nfc/NfcBaseActivity.java , 3487
AdNfcDemo/src/com/zchr/nfc/NfcReader.java , 3740
AdNfcDemo/src/com/zchr/nfcdemo/MainActivity.java , 2292
AdNfcDemo/src/com/zchr/util/MyUtil.java , 772
AdNfcDemo/src/com/zchr/util/SysException.java , 338
