删除无效代码
This commit is contained in:
parent
d28306b172
commit
ee929975b3
@ -2,9 +2,7 @@ using Android.App;
|
|||||||
using Android.Content;
|
using Android.Content;
|
||||||
using Android.Content.PM;
|
using Android.Content.PM;
|
||||||
using Android.Nfc;
|
using Android.Nfc;
|
||||||
using Android.Nfc.Tech;
|
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using Com.Lvcheng.Lock.Shared.Nfc.Example.Java;
|
|
||||||
using NFCLockDemoV2;
|
using NFCLockDemoV2;
|
||||||
using NFCLockDemoV2.Platforms.Android;
|
using NFCLockDemoV2.Platforms.Android;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@ -19,19 +17,11 @@ public class MainActivity : MauiAppCompatActivity
|
|||||||
private NFCLockHelper nfcHelper;
|
private NFCLockHelper nfcHelper;
|
||||||
private NFCCallbacks _callbacks;
|
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)
|
protected override void OnCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
base.OnCreate(savedInstanceState);
|
base.OnCreate(savedInstanceState);
|
||||||
_callbacks = new NFCCallbacks();
|
_callbacks = new NFCCallbacks();
|
||||||
nfcHelper = new NFCLockHelper(this, _callbacks);
|
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();
|
base.OnResume();
|
||||||
nfcHelper.OnResume();
|
nfcHelper.OnResume();
|
||||||
//if (_nfcAdapter != null)
|
|
||||||
//{
|
|
||||||
// _nfcAdapter.EnableForegroundDispatch(this, _pendingIntent, _intentFilters, _techLists);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPause()
|
protected override void OnPause()
|
||||||
{
|
{
|
||||||
base.OnPause();
|
base.OnPause();
|
||||||
nfcHelper.OnPause();
|
nfcHelper.OnPause();
|
||||||
//if (_nfcAdapter != null)
|
|
||||||
//{
|
|
||||||
// _nfcAdapter.DisableForegroundDispatch(this);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnNewIntent(Intent intent)
|
protected override void OnNewIntent(Intent intent)
|
||||||
{
|
{
|
||||||
base.OnNewIntent(intent);
|
base.OnNewIntent(intent);
|
||||||
nfcHelper.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user