As the title suggests, I would like to disable / hide all events related to NFC discovery.
My App don't use NFC and my goal is to hide automatic pop-ups, from Google Pay for example.
I find these threads here that help me to find a way to solution
1: Android app enable NFC only for one Activity
2: Android app enable NFC only for one Activity
This is my MainActivity:
[Activity(Label = "Title", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
//CrossNFC.Init(this);
var intent = new Intent(this, this.GetType()).AddFlags(ActivityFlags.SingleTop);
PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.Mutable);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
protected override void OnResume()
{
base.OnResume();
NfcAdapter nfcAdapter = NfcAdapter.GetDefaultAdapter(this);
var intent = new Intent(this, this.GetType()).AddFlags(ActivityFlags.SingleTop);
PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.Mutable);
nfcAdapter.EnableForegroundDispatch(this, pendingIntent, null, null);
//CrossNFC.OnResume();
}
protected override void OnPause()
{
base.OnPause();
NfcAdapter nfcAdapter = NfcAdapter.GetDefaultAdapter(this);
nfcAdapter.DisableForegroundDispatch(this);
}
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
if (NfcAdapter.ActionTagDiscovered.Equals(intent.Action))
return;
}
}
But when I try it(I have two NFC tags for testing and 1 App that works like NFC card emulation) with 1 I can catch the event onNewIntent but the other two are not even revealed.
If I use Plugin.NFC nugget, I can detect 2 of my 3 tags..
Am I doing something wrong?
Thanks