左晓为主开发手持机充值管理机
zuojincheng
2025-03-21 8521954fa97bdfc54123afb4a72755ece311db06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.dayu.general.tool
 
import android.app.Activity
import android.content.Intent
import com.dayu.baselibrary.tools.nfc.BaseNfcReadHelper
import com.dayu.baselibrary.tools.nfc.NfcReadAdapter
 
/**
 * NFC读取工具类的Kotlin实现
 */
class NfcReadHelper private constructor(intent: Intent, activity: Activity) : GeBaseHelper(activity) {
    
    private val adapter: NfcReadAdapter = NfcReadAdapter(intent, activity)
 
    companion object {
        private var helper: NfcReadHelper? = null
 
        /**
         * 单例初始化
         */
        @JvmStatic
        fun getInstance(intent: Intent, activity: Activity): NfcReadHelper {
            if (helper == null) {
                helper = NfcReadHelper(intent, activity)
            }
            return helper!!
        }
    }
 
 
 
    /**
     * 获取卡号
     */
    fun getCardNumber(): String {
        return try {
            adapter.cardNumber
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }
 
    /**
     * 获取卡片类型和卡号
     */
    fun getCardTypeAndCardNumber(): String {
        return try {
            adapter.cradTypeAndCardNumber
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }
 
    /**
     * 读取NFC卡的全部信息
     */
    fun getAllData(callback: BaseNfcReadHelper.NFCCallMapback) {
        try {
            adapter.getAllData(callback)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
 
    /**
     * 获取一个扇区的数据
     */
    fun getOneSectorData(): List<ByteArray>? {
        return try {
            adapter.onesectorData
        } catch (e: Exception) {
            e.printStackTrace()
            null
        }
    }
 
    /**
     * 读取NFC卡的特定扇区信息
     */
    fun getData(a: Int, b: Int, callback: BaseNfcReadHelper.NFCCallByteback) {
        try {
            adapter.getData(a, b, callback)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
 
 
}