package com.dayu.recharge.activity;
|
|
/**
|
* Created by zuo on 2018/12/2.
|
*/
|
|
|
import android.app.Activity;
|
import android.app.PendingIntent;
|
import android.content.Context;
|
import android.content.Intent;
|
import android.nfc.NdefMessage;
|
import android.nfc.NfcAdapter;
|
import android.nfc.NfcEvent;
|
import android.nfc.Tag;
|
import android.nfc.cardemulation.CardEmulation;
|
import android.os.Bundle;
|
import android.os.Handler;
|
import android.os.Message;
|
|
import com.dayu.recharge.card.UserCard;
|
import com.dayu.recharge.tools.LoyaltyCardReader;
|
import com.dayu.recharge.tools.NFCUtil;
|
import com.dayu.recharge.tools.NfcReadHelper;
|
import com.dayu.recharge.utils.LogUtil;
|
import com.dayu.recharge.utils.TipUtil;
|
import com.tencent.bugly.crashreport.CrashReport;
|
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* Author:Created by Ricky on 2017/8/25.
|
* Email:584182977@qq.com
|
* Description:
|
* 子类在onNewIntent方法中进行NFC标签相关操作。
|
* launchMode设置为singleTop或singelTask,保证Activity的重用唯一
|
* 在onNewIntent方法中执行intent传递过来的Tag数据
|
* 将NFC标签卡靠近手机后部(NFC标签卡可网上自行购买)
|
*/
|
public class BaseNfcActivity extends BaseActivity implements LoyaltyCardReader.AccountCallback {
|
|
/**
|
* 该卡已写入用户信息
|
*/
|
public final static int HAS_USER = 1;
|
/**
|
* 该卡未写入用户信息
|
*/
|
public final static int NO_USER = 2;
|
/**
|
* 充值
|
*/
|
public final static int RECHARGE = 3;
|
|
public final static int ERROR = -1;
|
|
// protected NfcAdapter mNfcAdapter;
|
// private PendingIntent mPendingIntent;
|
|
volatile UserCard userCard;
|
Handler handler;
|
|
public LoyaltyCardReader mLoyaltyCardReader;
|
|
NFCUtil nfcUtil;
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
nfcUtil = NFCUtil.getInstance();
|
nfcUtil.setAccountCallback(this);
|
}
|
|
/**
|
* onCreat->onStart->onResume->onPause->onStop->onDestroy
|
* 启动Activity,界面可见时.
|
*/
|
|
|
@Override
|
protected void onStart() {
|
super.onStart();
|
//此处adapter需要重新获取,否则无法获取message
|
nfcUtil.onStartNfcAdapter(this);
|
|
}
|
|
/**
|
* 获得焦点,按钮可以点击
|
*/
|
@Override
|
public void onResume() {
|
super.onResume();
|
nfcUtil.onResumeNfcAdapter(this);
|
}
|
|
/**
|
* 暂停Activity,界面获取焦点,按钮可以点击
|
*/
|
@Override
|
public void onPause() {
|
super.onPause();
|
//恢复默认状态
|
nfcUtil.onPauseNfcAdapter(this);
|
}
|
|
|
@Override
|
public void physicalCardDoing(Tag tag) {
|
|
}
|
|
@Override
|
public void virtualCardDoing(Tag tag) {
|
|
}
|
}
|