public void StartListening(bool Write) { if (!IsAvailable()) { throw new InvalidOperationException("NFC not available"); } if (!IsEnabled()) // todo: offer possibility to open dialog { throw new InvalidOperationException("NFC is not enabled"); } WriteMode = Write; var ndefDetected = new IntentFilter(NfcAdapter.ActionNdefDiscovered); ndefDetected.AddDataType("*/*"); var tagDetected = new IntentFilter(NfcAdapter.ActionTagDiscovered); tagDetected.AddDataType("*/*"); var filters = new[] { tagDetected }; var intent = new Intent(CurrentActivity, CurrentActivity.GetType()).AddFlags(ActivityFlags.SingleTop); var pendingIntent = PendingIntent.GetActivity(CurrentActivity, 0, intent, 0); _nfcAdapter.EnableForegroundDispatch(CurrentActivity, pendingIntent, filters, new[] { new[] { Java.Lang.Class.FromType(typeof(MifareUltralight)).Name } }); Enabled = true; //_nfcAdapter.EnableReaderMode(activity, this, NfcReaderFlags.NfcA | NfcReaderFlags.NoPlatformSounds, null); }
/// <summary> /// Starts tags detection /// </summary> public void StartListening() { if (_nfcAdapter == null) { return; } var intent = new Intent(CurrentActivity, CurrentActivity.GetType()).AddFlags(ActivityFlags.SingleTop); var pendingIntent = PendingIntent.GetActivity(CurrentActivity, 0, intent, 0); var ndefFilter = new IntentFilter(NfcAdapter.ActionNdefDiscovered); ndefFilter.AddDataType("*/*"); var tagFilter = new IntentFilter(NfcAdapter.ActionTagDiscovered); tagFilter.AddCategory(Intent.CategoryDefault); var filters = new IntentFilter[] { ndefFilter, tagFilter }; _nfcAdapter.EnableForegroundDispatch(CurrentActivity, pendingIntent, filters, null); _isListening = true; OnTagListeningStatusChanged?.Invoke(_isListening); }
/// <inheritdoc/> public Task StartListeningAsync() { if (!Enabled) { throw new InvalidOperationException("NFC not available"); } if (!Available) // todo: offer possibility to open dialog { throw new InvalidOperationException("NFC is not enabled"); } var activity = (Activity)Association; var tagDetected = new IntentFilter(NfcAdapter.ActionNdefDiscovered); tagDetected.AddDataType("*/*"); var filters = new[] { tagDetected }; var intent = new Intent(activity, activity.GetType()).AddFlags(ActivityFlags.SingleTop); var pendingIntent = PendingIntent.GetActivity(activity, 0, intent, 0); _adapter.EnableForegroundDispatch(activity, pendingIntent, filters, new[] { new[] { Java.Lang.Class.FromType(typeof(Ndef)).Name } }); Scanning = true; Debug.WriteLine("Started Listening Async - XNFC"); return(Task.CompletedTask); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); mms = new MMSReceiver(); sms = new SMSReceiver(); var filter2 = new IntentFilter("android.provider.Telephony.WAP_PUSH_RECEIVED"); filter2.AddDataType("application/vnd.wap.mms-message"); RegisterReceiver(mms, filter2); var filter3 = new IntentFilter("android.provider.Telephony.MMS_RECEIVED"); RegisterReceiver(mms, filter3); var filter1 = new IntentFilter("android.provider.Telephony.SMS_RECEIVED"); RegisterReceiver(sms, filter1); Button button = FindViewById <Button>(Resource.Id.button1); button.Click += Btn_Click; }
private static void addDataTypeUnchecked(IntentFilter filter, string type) { try { filter.AddDataType(type); } catch (Android.Content.IntentFilter.MalformedMimeTypeException ex) { throw new RuntimeException(ex); } }
public static void Something() { PendingIntent pendingIntent = PendingIntent.GetActivity(_Context, 0, new Intent(_Context, _Context.GetType()).AddFlags(ActivityFlags.SingleTop), 0); IntentFilter ndef = new IntentFilter(NfcAdapter.ActionNdefDiscovered); try { ndef.AddDataType("*/*"); /* Handles all MIME based dispatches. * You should specify only the ones that you need. */ } catch (MalformedMimeTypeException e) { throw new Java.Lang.RuntimeException("fail", e); } intentFiltersArray = new IntentFilter[] { ndef, }; //techListsArray = new string[][] { new string[] { NfcF.class.getName() }}; }
protected override void OnResume() { base.OnResume(); IntentFilter smsIntentfilter = new IntentFilter(Android.Provider.Telephony.Sms.Intents.SmsReceivedAction) { Priority = (int)IntentFilterPriority.HighPriority }; IntentFilter mmsIntentfilter = new IntentFilter(Android.Provider.Telephony.Sms.Intents.WapPushReceivedAction) { Priority = (int)IntentFilterPriority.HighPriority }; mmsIntentfilter.AddDataType("application/vnd.wap.mms-message"); RegisterReceiver(smsReceiver, smsIntentfilter); RegisterReceiver(mmsReceiver, mmsIntentfilter); }
private Task StartWithFilters(IEnumerable <string> filterActions, IEnumerable <string> filterTechs, PendingIntent activity, Activity association) { IntentFilter intentFilter = new IntentFilter(); foreach (var action in filterActions) { intentFilter.AddAction(action); } intentFilter.AddDataType("*/*"); IntentFilter[] filters = new IntentFilter[1] { intentFilter }; _adapter.EnableForegroundDispatch(association, activity, filters, new string[1][] { filterTechs.ToArray() }); return(Task.CompletedTask); }
private void EnableNfc() { if (_isNfcEnabled) { return; } var adapter = Android.Nfc.NfcAdapter.GetDefaultAdapter(_mainActivity); if (adapter != null) { // Filter out NDEF intents. In this library we are not interested in Tech or Tag low level intents. // Android prioritize the filters in the following order: // - ActionNdefDiscovered // - ActionTechDiscovered // - ActionTagDiscovered var pendingIntent = PendingIntent.GetActivity( _mainActivity, 0, new Intent(_mainActivity, _mainActivity.GetType()).AddFlags(ActivityFlags.SingleTop), 0); var ndefFilter = new IntentFilter(Android.Nfc.NfcAdapter.ActionNdefDiscovered); ndefFilter.AddDataType("*/*"); var filters = new IntentFilter[] { ndefFilter, }; adapter.EnableForegroundDispatch( _mainActivity, pendingIntent, filters, null); } _isNfcEnabled = true; System.Diagnostics.Debug.WriteLine("========> NFC Enabled"); }
public async Task StartListeningAsync() { if (!await IsAvailableAsync()) { throw new InvalidOperationException("NFC not available"); } if (!await IsEnabledAsync()) // todo: offer possibility to open dialog { throw new InvalidOperationException("NFC is not enabled"); } var activity = CrossNfc.CurrentActivity; var tagDetected = new IntentFilter(NfcAdapter.ActionNdefDiscovered); tagDetected.AddDataType("*/*"); var filters = new[] { tagDetected }; var intent = new Intent(activity, activity.GetType()).AddFlags(ActivityFlags.SingleTop); var pendingIntent = PendingIntent.GetActivity(activity, 0, intent, 0); _nfcAdapter.EnableForegroundDispatch(activity, pendingIntent, filters, new[] { new[] { Java.Lang.Class.FromType(typeof(Ndef)).Name } }); //_nfcAdapter.EnableReaderMode(activity, this, NfcReaderFlags.NfcA | NfcReaderFlags.NoPlatformSounds, null); }
public async Task StartReadingAsync() { if (!await IsReaderAvailableAsync()) { throw new InvalidOperationException("NFC reader not available"); } if (!await IsReaderEnabledAsync()) { throw new InvalidOperationException("NFC reader is not enabled"); } var act = CurrentActivity; var tagDetected = new IntentFilter(NfcAdapter.ActionNdefDiscovered); tagDetected.AddDataType("*/*"); var filters = new[] { tagDetected }; var intent = new Intent(act, act.GetType()).AddFlags(ActivityFlags.SingleTop); var pendingIntent = PendingIntent.GetActivity(act, 0, intent, 0); _nfcAdapter.EnableReaderMode(act, this, NfcReaderFlags.NfcA | NfcReaderFlags.NoPlatformSounds, null); }