| | |
| | | |
| | | import com.dayu.baselibrary.bean.BaseUserCardCard; |
| | | import com.dayu.baselibrary.tools.HexUtil; |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | | import java.io.IOException; |
| | | |
| | |
| | | |
| | | private static NativeNfcWriteHelper helper; |
| | | |
| | | public NativeNfcWriteHelper(Intent intent, Activity activity) { |
| | | } |
| | | |
| | | public void setIntent(Intent intent) { |
| | | this.tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); |
| | |
| | | */ |
| | | public static NativeNfcWriteHelper getInstence(Intent intent, Activity activity) { |
| | | if (helper == null) { |
| | | helper = new NativeNfcWriteHelper(intent, activity); |
| | | helper = new NativeNfcWriteHelper(); |
| | | } |
| | | helper.setIntent(intent); |
| | | return helper; |
| | |
| | | |
| | | @Override |
| | | public boolean writeData(byte[] str, int a, int b, NFCCallBack callBack) { |
| | | return writeData(str, a, b, true, null); |
| | | } |
| | | |
| | | @Override |
| | | public boolean writeData(byte[] str, int a, int b, boolean isConnect, NFCCallBack callBack) { |
| | | Log.i("NFCWreatActivity", "writeData: a=" + a + " b=" + b); |
| | | if (str.length == 16) { |
| | | try { |
| | |
| | | if (null != mfc) { |
| | | try { |
| | | //连接NFC |
| | | mfc.connect(); |
| | | if (isConnect) { |
| | | mfc.connect(); |
| | | } |
| | | //获取扇区数量 |
| | | int count = mfc.getSectorCount(); |
| | | //如果传进来的扇区大了或者小了直接退出方法 |
| | |
| | | } |
| | | } |
| | | } else if (listA_PS.size() != 0 && listA_PS.size() > a) { |
| | | if (mfc.authenticateSectorWithKeyA(0, listA_PS.get(a))) { |
| | | if (mfc.authenticateSectorWithKeyA(a, defauleKey)) { |
| | | isOpen = true; |
| | | if (listKeyA.get(a).equals(defauleKey)) { |
| | | //当前为默认白卡密码时写卡时修改密码 |
| | | changePasword(a, mfc); |
| | | } |
| | | |
| | | } else if (mfc.authenticateSectorWithKeyA(a, listA_PS.get(a))) { |
| | | isOpen = true; |
| | | } |
| | | } |
| | | if (isOpen) { |
| | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | callBack.isSusses(false, a + "扇区写卡报错" + e.getMessage()); |
| | | if (callBack != null) { |
| | | callBack.isSusses(false, a + "扇区写卡报错" + e.getMessage()); |
| | | } |
| | | return false; |
| | | } |
| | | } else { |
| | | callBack.isSusses(false, a + "扇区写卡报错,byte数组大小不为16"); |
| | | if (callBack != null) { |
| | | callBack.isSusses(false, a + "扇区写卡报错,byte数组大小不为16"); |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | |
| | | public boolean changePasword(int a,byte[] passWord, MifareClassic mfc) { |
| | | try { |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | CrashReport.postCatchedException(e); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 初始化卡 |
| | | * |