左晓为主开发手持机充值管理机
zuojincheng
2025-03-26 1bc1acff2127d61b359800096ad5b904370d9176
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
package com.dayu.general.tool
 
import android.app.Activity
import android.content.Intent
import com.dayu.baselibrary.tools.nfc.NFCCallBack
import com.dayu.baselibrary.tools.nfc.NfcWriteAdapter
import com.dayu.general.bean.card.UserCard
 
class NfcWreatHelper private constructor(intent: Intent, activity: Activity) : GeBaseHelper(activity) {
 
    private val adapter: NfcWriteAdapter = NfcWriteAdapter(intent, activity)
 
    companion object {
        private var helper: NfcWreatHelper? = null
 
        /**
         * 单例初始化
         */
        @JvmStatic
        fun getInstance(intent: Intent, activity: Activity): NfcWreatHelper {
            if (helper == null) {
                helper = NfcWreatHelper(intent, activity)
            }
            helper!!.adapter.setIntent(intent)
            return helper!!
        }
    }
 
 
    /**
     * 写卡
     *
     * @param str 书写内容,16个字节
     * @param a   书写的扇区 (从0开始数)
     * @param b   书写的块(从0开始数)
     * @param
     */
    fun writeData(str: ByteArray?, a: Int, b: Int,callBack: NFCCallBack): Boolean {
        try {
            return adapter.writeData(str, a, b,callBack)
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return false
    }
 
    /**
     * 写卡
     *
     * @param userCard 用户卡内容
     * @param
     */
    fun writeUserData(userCard: UserCard): Boolean {
        try {
            return adapter.writeUserData(userCard,7)
        } catch (e: java.lang.Exception) {
            e.printStackTrace()
        }
        return false
    }
 
 
}