From ee929975b3f7e7ba05b3d08ec68dff1093e78386 Mon Sep 17 00:00:00 2001 From: denggaofeng <1139968554@qq.com> Date: Tue, 21 Apr 2026 10:49:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E6=95=88=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Platforms/Android/MainActivity.cs | 98 ------------------- 1 file changed, 98 deletions(-) diff --git a/NFCLockDemoV2/Platforms/Android/MainActivity.cs b/NFCLockDemoV2/Platforms/Android/MainActivity.cs index 8a72280..6ab8dfe 100644 --- a/NFCLockDemoV2/Platforms/Android/MainActivity.cs +++ b/NFCLockDemoV2/Platforms/Android/MainActivity.cs @@ -2,9 +2,7 @@ using Android.App; using Android.Content; using Android.Content.PM; using Android.Nfc; -using Android.Nfc.Tech; using Android.OS; -using Com.Lvcheng.Lock.Shared.Nfc.Example.Java; using NFCLockDemoV2; using NFCLockDemoV2.Platforms.Android; using System.Diagnostics; @@ -19,19 +17,11 @@ public class MainActivity : MauiAppCompatActivity private NFCLockHelper nfcHelper; private NFCCallbacks _callbacks; - //private NfcAdapter _nfcAdapter; - //private PendingIntent _pendingIntent; - //private string[][] _techLists = [[typeof(NfcA).FullName, typeof(NdefFormatable).FullName, typeof(MifareUltralight).FullName]]; - //private IntentFilter[] _intentFilters = [new(NfcAdapter.ActionNdefDiscovered), new(NfcAdapter.ActionTechDiscovered), new(NfcAdapter.ActionTagDiscovered)]; - //private volatile bool _processing = false; - protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); _callbacks = new NFCCallbacks(); nfcHelper = new NFCLockHelper(this, _callbacks); - //_nfcAdapter = NfcAdapter.GetDefaultAdapter(this); - //_pendingIntent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(MainActivity)).AddFlags(ActivityFlags.ReceiverReplacePending), PendingIntentFlags.Mutable); } @@ -39,106 +29,18 @@ public class MainActivity : MauiAppCompatActivity { base.OnResume(); nfcHelper.OnResume(); - //if (_nfcAdapter != null) - //{ - // _nfcAdapter.EnableForegroundDispatch(this, _pendingIntent, _intentFilters, _techLists); - //} } protected override void OnPause() { base.OnPause(); nfcHelper.OnPause(); - //if (_nfcAdapter != null) - //{ - // _nfcAdapter.DisableForegroundDispatch(this); - //} } protected override void OnNewIntent(Intent intent) { base.OnNewIntent(intent); nfcHelper.OnNewIntent(intent); - //if (!_processing) - //{ - // if (intent != null && (intent.Action == NfcAdapter.ActionNdefDiscovered || - // intent.Action == NfcAdapter.ActionTechDiscovered || - // intent.Action == NfcAdapter.ActionTagDiscovered)) - // { - - // Task.Run(async () => - // { - // try - // { - // _processing = true; - // Tag? tag = intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag; - // if (tag != null) - // { - // NfcA? nfcA = NfcA.Get(tag); - // if (nfcA != null) - // { - // nfcA.Connect(); - // nfcA.Timeout = 1000; - // Process(nfcA); - // } - // } - // } - // catch (Exception e) - // { - // _callbacks.OnLost(); - // Console.WriteLine(e); - // } - // finally - // { - // await Task.Delay(2000); - // _processing = false; - // _callbacks.OnFinished(); - // } - // }); - // } - //} - - } - - private void Process(NfcA nfcA) - { - DeviceManagerWrapper wrapper = new DeviceManagerWrapper(nfcA); - - try - { - Com.Lvcheng.Lock.Shared.Nfc.Result initRes = wrapper.Init(); - if (initRes.Equals(Com.Lvcheng.Lock.Shared.Nfc.Result.Ok)) - { - long? id; - bool? isNew; - int? mRssi; - - // 无限循环,替代 do-while - while (true) - { - Com.Lvcheng.Lock.Shared.Nfc.Result getInfoRes = wrapper.Info; - if (!getInfoRes.Equals(Com.Lvcheng.Lock.Shared.Nfc.Result.Ok)) - return; - - _ = wrapper.Rssi; - id = wrapper.MGetId().LongValue(); - isNew = wrapper.MGetIsNew().BooleanValue(); - mRssi = wrapper.MGetRssi().IntValue(); - - // 判断是否继续循环 - bool continueLoop = _callbacks.OnLoop(wrapper, id, isNew, mRssi); - System.Diagnostics.Debug.WriteLine("continueLoop:" + continueLoop); - - // 不继续就退出循环 - if (!continueLoop) - break; - } - } - } - catch (Exception e) - { - Console.WriteLine(e); - } } } \ No newline at end of file