91 lines
2.5 KiB
Java
91 lines
2.5 KiB
Java
package com.arpa.hndahesudintocctmsdriver.ui;
|
|
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.util.Log;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import com.alct.mdp.MDPLocationCollectionManager;
|
|
import com.alct.mdp.callback.OnResultListener;
|
|
import com.arpa.hndahesudintocctmsdriver.R;
|
|
import com.arpa.hndahesudintocctmsdriver.util.NfcUtils;
|
|
import com.arpa.hndahesudintocctmsdriver.util.view.BaseAppCompatActivity;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
/**
|
|
* @author hlh
|
|
* @version 1.0.0
|
|
* @date 2022/2/15 17:03
|
|
* @description:
|
|
*/
|
|
public class NFCActivity extends BaseAppCompatActivity {
|
|
|
|
private TextView get;
|
|
|
|
@Override
|
|
protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_nfc);
|
|
con=this;
|
|
get=findViewById(R.id.get);
|
|
if (!NfcUtils.hasNfc(con)) {
|
|
Toast.makeText(con,"请先开启nfc",Toast.LENGTH_LONG).show();
|
|
}else{
|
|
initData();
|
|
}
|
|
|
|
}
|
|
|
|
public void initData() {
|
|
//nfc初始化设置
|
|
NfcUtils nfcUtils = new NfcUtils(this);
|
|
}
|
|
|
|
@Override
|
|
protected void onResume() {
|
|
super.onResume();
|
|
//开启前台调度系统
|
|
//NfcUtils.mNfcAdapter.enableForegroundDispatch(this, NfcUtils.mPendingIntent, NfcUtils.mIntentFilter, NfcUtils.mTechList);
|
|
}
|
|
|
|
@Override
|
|
protected void onPause() {
|
|
super.onPause();
|
|
//关闭前台调度系统
|
|
// NfcUtils.mNfcAdapter.disableForegroundDispatch(this);
|
|
}
|
|
|
|
String str="";
|
|
|
|
@Override
|
|
protected void onNewIntent(Intent intent) {
|
|
super.onNewIntent(intent);
|
|
//当该Activity接收到NFC标签时,运行该方法
|
|
//调用工具方法,读取NFC数据
|
|
try {
|
|
str = NfcUtils.readNFCId(intent);
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
}
|
|
get.setText("读取内容"+str);
|
|
MDPLocationCollectionManager.checkNfc(getBaseContext(), "123456", str, new OnResultListener() {
|
|
@Override
|
|
public void onSuccess() {
|
|
get.setText("读取内容"+str+"成功");
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(String s, String s1) {
|
|
get.setText("读取内容"+str+"失败"+s+s1);
|
|
|
|
}
|
|
});
|
|
Log.e("nfc",str);
|
|
}
|
|
|
|
}
|