Witam.
W aplikacji pisanej w Xamarinie (C#) pod Androida piszę obsługę odczytu kart mifare z czytnika NFC.
Znalazłem o tym parę artykułów, udało mi się uzyskać efekt odczytu Tag'a NFC ale dostaję tag bez danych.
Mam karty mifare zakodowane tak, że gdy odczytuję kartę w czytniku mifare pod windowsem to dostaję zapisany na niej kod w postaci tekstu (czytnik symuluje klawiaturę).
Natomiast w Xamarinie dostaję tag, w którym wypelnione jest pole Id a pozostałe pola są ustawione na false a pole NdefMessage ma wartość null.
Co muszę zrobić aby otrzymać dane z tego tag'a?
Próbowałem stosować różne filtry na inicjalizacji NFC ale to nic nie dawało aż w końcu wyłączyłem filtr.
Może ktoś mi podpowie jak odczytać zawartość takiej karty?
Poniżej kod inicjalizujący nfc:
[MetaData(NfcAdapter.ActionTechDiscovered, Resource = "@xml/nfc_tech_filter")]
[IntentFilter(new[] { NfcAdapter.ActionNdefDiscovered }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "text/plain")]
[IntentFilter(new[] { NfcAdapter.ExtraData }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "text/plain")]
[IntentFilter(new[] { NfcAdapter.ExtraNdefMessages }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "text/plain")]
[IntentFilter(new[] { NfcAdapter.ActionTagDiscovered }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "text/plain")]
[Activity(Label = "SMM", MainLauncher = true, Icon = "@mipmap/icon", Theme = "@style/MyTheme.Splash", ScreenOrientation = ScreenOrientation.Locked, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
public NfcAdapter NFCdevice;
public NfcForms x;
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Rg.Plugins.Popup.Popup.Init(this);
SharpnadoInitializer.Initialize();
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
#region Ukrywanie dolnego paska
int uiOptions = (int)Window.DecorView.SystemUiVisibility;
uiOptions |= (int)SystemUiFlags.LowProfile;
uiOptions |= (int)SystemUiFlags.Fullscreen;
uiOptions |= (int)SystemUiFlags.HideNavigation;
uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
#endregion
NfcManager NfcManager = (NfcManager)Android.App.Application.Context.GetSystemService(Context.NfcService);
NFCdevice = NfcManager.DefaultAdapter;
Xamarin.Forms.DependencyService.Register<INfcForms, NfcForms>();
x = Xamarin.Forms.DependencyService.Get<INfcForms>() as NfcForms;
LoadApplication(new App());
}
protected override void OnResume()
{
base.OnResume();
#region NFC
if (NFCdevice != null)
{
try
{
var intent = new Intent(this, GetType()).AddFlags(ActivityFlags.SingleTop);
NFCdevice.EnableForegroundDispatch
(
this,
PendingIntent.GetActivity(this, 0, intent, 0),
null,
null
);
}
catch
{ }
}
#endregion
}
protected override void OnPause()
{
base.OnPause();
if (NFCdevice != null)
NFCdevice.DisableForegroundDispatch(this);
}
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
if (x != null)
x.OnNewIntent(this, intent);
}
}
Poniżej kod, który przejmuje odczyt karty na dodatkowej stronie:
private INfcForms device = null;
private void LoadNFC()
{
try
{
device = DependencyService.Get<INfcForms>();
device.NewTag += HandleNewTag;
}
catch (Exception exp)
{
}
}
void HandleNewTag(object sender, NfcFormsTag e)
{
if (e.NdefMessage != null && e.NdefMessage.Count > 0)
{
}
}
Czy ktoś mógłby mi pomóc?