1.初始化 if ((null != mNfcAdapter) && !mNfcAdapter.isEnabled()) {
Toast.makeText(this, "请在系统设置中先启用NFC功能", Toast.LENGTH_SHORT).show();
startActivity(new Intent(Settings.ACTION_NFC_SETTINGS));
finish();
return;
}
mNfcPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,
getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
mNFCReaderHelper = new NFCReaderHelper(this, uiHandler, appKey,
appSecret, true);
2.异步读取身份证
private class NFCReadTask extends AsyncTask<Void, Void, String> {
private Intent mIntent = null;
private Context context = null;
private long beginTime;
public NFCReadTask(Intent i, Context contextTemp) {
mIntent = i;
context = contextTemp;
}
@Override
protected String doInBackground(Void... params) {
beginTime = System.currentTimeMillis();
String strCardInfo = mNFCReaderHelper.readCardWithIntent(mIntent);
// 获取uuid String uuid = mNFCReaderHelper.readCardUUId(mIntent);
return uuid + "," + strCardInfo;
}
@Override
protected void onPostExecute(String strCardInfo) {
super.onPostExecute(strCardInfo);
String uuid = "";
try {
uuid = strCardInfo.split(",")[0];
strCardInfo = strCardInfo.split(",")[1];
} catch (Exception ex) {
}
uuIdText.setText(uuid);
tvshijiancontent.setText((System.currentTimeMillis() - beginTime)
+ "毫秒");
if ((null != strCardInfo) && (strCardInfo.length() > 1600)) {
UserInfo userInfo = mNFCReaderHelper .
parsePersonInfoNew(strCardInfo);
tvname.setText(userInfo.name);
tvsex.setText(userInfo.sex);
tvnation.setText(userInfo.nation);
tvbirthday.setText(userInfo.brithday);
tvcode.setText(userInfo.id);
tvaddress.setText(userInfo.address);
tvdate.setText(userInfo.exper + "-" + userInfo.exper2);
tvdepar.setText(userInfo.issue);
// TODO:
if (isLocalParsingImage) {
// 本地动态库解析//
Bitmap bm = mNFCReaderHelper.decodeImagexxxXT(strCardInfo);
Bitmap bm = mNFCReaderHelper.decodeImagexxxNewBit(strCardInfo); iv_zhaopian.setImageBitmap(bm);
} else {
// 网络解析头像
ShowHeadThread showThread = new ShowHeadThread();
showThread.img = mNFCReaderHelper
.decodeImageByte(strCardInfo);
showThread.start();
}
}
}
}
3、SDK源码地址: http://dc.jsske.com:9080/nfcreader/a/nfc/authcode/userTrial