3using Android.Content.PM;
7using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
15 [Activity(Theme =
"@style/Maui.SplashTheme", MainLauncher =
true,
16 ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density | ConfigChanges.Locale,
17 ScreenOrientation = ScreenOrientation.Portrait, LaunchMode = LaunchMode.SingleTop)]
18 [IntentFilter([NfcAdapter.ActionNdefDiscovered],
19 Categories = [Intent.CategoryDefault], DataMimeType =
"*/*")]
20 [IntentFilter([Intent.ActionView],
21 Categories = [Intent.CategoryDefault, Intent.CategoryBrowsable],
22 DataSchemes = [
"iotid",
"iotdisco",
"iotsc",
"tagsign",
"obinfo",
"edaler",
"nfeat",
"xmpp",
"aes256",
"neuroaccess"])]
25 private static NfcAdapter? nfcAdapter =
null;
27 protected override async
void OnPostCreate(Bundle? savedInstanceState)
31 base.OnPostCreate(savedInstanceState);
32 await this.HandleIntent(this.Intent);
33 nfcAdapter = NfcAdapter.GetDefaultAdapter(
this);
38 StringBuilder msg =
new();
40 msg.AppendLine(
"An error occurred in the Android MainActivity.OnPostCreate method.");
41 msg.AppendLine(
"Exception message:");
42 msg.Append(ex.Message);
44 msg.AppendLine(
"```");
45 msg.AppendLine(ex.StackTrace);
46 msg.AppendLine(
"```");
48 App.SendAlert(msg.ToString(),
"text/plain").Wait();
51 App.
Current?.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
55 protected override void OnResume()
59 if (nfcAdapter is not
null)
61 Intent Intent =
new Intent(
this, this.GetType()).AddFlags(ActivityFlags.SingleTop);
63 PendingIntent? PendingIntent = PendingIntent.GetActivity(
this, 0, Intent, PendingIntentFlags.Mutable);
64 nfcAdapter.EnableForegroundDispatch(
this, PendingIntent,
null,
null);
67 this.RemoveAllNotifications();
70 protected override void OnPause()
73 nfcAdapter?.DisableForegroundDispatch(
this);
76 protected override async
void OnNewIntent(Intent? Intent)
78 base.OnNewIntent(Intent);
79 await this.HandleIntent(Intent);
82 async Task HandleIntent(Intent? Intent)
89 switch (Intent.Action)
91 case Intent.ActionView:
92 string? Url = Intent?.Data?.ToString();
93 Console.WriteLine(Url);
94 if (!
string.IsNullOrEmpty(Url))
98 case NfcAdapter.ActionTagDiscovered:
99 case NfcAdapter.ActionNdefDiscovered:
100 case NfcAdapter.ActionTechDiscovered:
101 Tag? Tag = Intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag;
105 byte[]? ID = Tag.GetId();
109 string[]? TechList = Tag.GetTechList();
110 if (TechList is
null)
113 List<INfcInterface> Interfaces = [];
115 foreach (
string Tech
in TechList)
119 case "android.nfc.tech.IsoDep":
120 IsoDep? IsoDep = IsoDep.Get(Tag);
121 if (IsoDep is not
null)
122 Interfaces.Add(
new IsoDepInterface(Tag, IsoDep));
125 case "android.nfc.tech.MifareClassic":
126 MifareClassic? MifareClassic = MifareClassic.Get(Tag);
127 if (MifareClassic is not
null)
128 Interfaces.Add(
new MifareClassicInterface(Tag, MifareClassic));
131 case "android.nfc.tech.MifareUltralight":
132 MifareUltralight? MifareUltralight = MifareUltralight.Get(Tag);
133 if (MifareUltralight is not
null)
134 Interfaces.Add(
new MifareUltralightInterface(Tag, MifareUltralight));
137 case "android.nfc.tech.Ndef":
138 Ndef? Ndef = Ndef.Get(Tag);
139 if (Ndef is not
null)
140 Interfaces.Add(
new NdefInterface(Tag, Ndef));
143 case "android.nfc.tech.NdefFormatable":
144 NdefFormatable? NdefFormatable = NdefFormatable.Get(Tag);
145 if (NdefFormatable is not
null)
146 Interfaces.Add(
new NdefFormatableInterface(Tag, NdefFormatable));
149 case "android.nfc.tech.NfcA":
150 NfcA? NfcA = NfcA.Get(Tag);
151 if (NfcA is not
null)
152 Interfaces.Add(
new NfcAInterface(Tag, NfcA));
155 case "android.nfc.tech.NfcB":
156 NfcB? NfcB = NfcB.Get(Tag);
157 if (NfcB is not
null)
158 Interfaces.Add(
new NfcBInterface(Tag, NfcB));
161 case "android.nfc.tech.NfcBarcode":
162 NfcBarcode? NfcBarcode = NfcBarcode.Get(Tag);
163 if (NfcBarcode is not
null)
164 Interfaces.Add(
new NfcBarcodeInterface(Tag, NfcBarcode));
167 case "android.nfc.tech.NfcF":
168 NfcF? NfcF = NfcF.Get(Tag);
169 if (NfcF is not
null)
170 Interfaces.Add(
new NfcFInterface(Tag, NfcF));
173 case "android.nfc.tech.NfcV":
174 NfcV? NfcV = NfcV.Get(Tag);
175 if (NfcV is not
null)
176 Interfaces.Add(
new NfcVInterface(Tag, NfcV));
182 await Service.
TagDetected(
new NfcTag(ID, [.. Interfaces]));
193 private void RemoveAllNotifications()
195 NotificationManager? Manager = (NotificationManager?)this.GetSystemService(NotificationService);
196 Manager?.CancelAll();
The Application class, representing an instance of the Neuro-Access app.
override async void OnResume()
static void OpenUrlSync(string Url)
Opens an URL in the application.
static new? App Current
Gets the current application, type casted to App.
Static class managing the application event log. Applications and services log events on this static ...
static void Critical(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs a critical event.
Interface for the Near-Field Communication (NFC) Service.
Task TagDetected(INfcTag Tag)
Method called when a new NFC Tag has been detected.