public void Init(bool prepareForScan = false) { if (MainActivity == null) { throw new Exception("MainActivity not set"); } if (prepareForScan) { PrepareForScan(LogMessage2); } BluetoothManager = (BluetoothManager)MainActivity.GetSystemService(Context.BluetoothService); BluetoothAdapter = BluetoothManager.Adapter; ScanCallback = new BluetoothScanCallback(MainActivity, this); MainActivity.Receiver = new BLEBroadcastReceiver(MainActivity, this); GattCallback = new LEGattCallback(MainActivity, this); var nfcManager = (NfcManager)MainActivity.GetSystemService(Context.NfcService); Log.Info(TAG + Operation, $"nfcManager => {nfcManager.ToString()}"); NfcAdapter = NfcAdapter.GetDefaultAdapter(MainActivity); Context = MainActivity; InitializeStatus(); if (BluetoothAdapter != null) { IntentFilter mfFilter = new IntentFilter(BluetoothDevice.ActionAclConnected); mfFilter.AddAction(BluetoothDevice.ActionPairingRequest); mfFilter.AddAction(BluetoothDevice.ActionBondStateChanged); mfFilter.AddAction(BluetoothDevice.ActionFound); mfFilter.AddAction(BluetoothAdapter.ActionDiscoveryFinished); mfFilter.Priority = (int)IntentFilterPriority.HighPriority; MainActivity.RegisterReceiver(MainActivity.Receiver, mfFilter); } MainActivity.PendingIntent = PendingIntent.GetActivity(MainActivity, 0, new Intent(MainActivity, MainActivity.GetType()).AddFlags(ActivityFlags.SingleTop), 0); asm = MainActivity.Resources.Assets; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); NfcManager NfcManager = (NfcManager)Android.App.Application.Context.GetSystemService(Context.NfcService); NFCdevice = NfcManager.DefaultAdapter; Xamarin.Forms.DependencyService.Register <INfcForms, NfcForms>(); PlatformSingleton.Instance.PlatformServiceList.Add <FingerPrintService>(null); PlatformSingleton.Instance.PlatformServiceList.Add <NFCService>(NfcManager); global::Xamarin.Forms.Forms.Init(this, bundle); x = Xamarin.Forms.DependencyService.Get <INfcForms>() as NfcForms; UserDialogs.Init(this); LoadApplication(new App()); }
private void EnableDispatch() { Intent intent = Intent; intent.AddFlags(ActivityFlags.SingleTop); PendingIntent tagIntent = PendingIntent.GetActivity( this, 0, intent, 0); IntentFilter iso = new IntentFilter(NfcAdapter.ActionNdefDiscovered); NfcAdapter adapter = NfcAdapter.GetDefaultAdapter(this); if (adapter == null) { Toast.MakeText(this, Resource.String.yubichallenge_no_nfc, ToastLength.Long).Show(); return; } if (adapter.IsEnabled) { // register for foreground dispatch so we'll receive tags according to our intent filters adapter.EnableForegroundDispatch( this, tagIntent, new IntentFilter[] { iso }, new String[][] { new String[] { Java.Lang.Class.FromType(typeof(IsoDep)).Name } } ); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.SetTitle(Resource.String.yubichallenge_nfc_off); dialog.SetPositiveButton(Android.Resource.String.Yes, (sender, args) => { Intent settings = new Intent(Android.Provider.Settings.ActionNfcSettings); StartActivity(settings); ((Dialog)sender).Dismiss(); }); dialog.SetNegativeButton(Android.Resource.String.No, (sender, args) => { ((Dialog)sender).Dismiss(); }); dialog.Show(); } }
private void InitNfc() { var nfcManager = (NfcManager)GetSystemService(NfcService); nfcAdapter = nfcManager.DefaultAdapter; if (nfcAdapter == null) { scanButton.Enabled = false; LogMessage("It seems like this device does not have an NFC Adapter."); } else { ShowNfcAvailability(); // Register Broadcast Intent listener when NFC Adapter state changes adapterStateMonitor = new NfcAdapterStateMonitor(this); RegisterReceiver(adapterStateMonitor, new IntentFilter(NfcAdapter.ActionAdapterStateChanged)); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); buttonLaunch = FindViewById <Button>(Resource.Id.buttonLaunch); buttonLaunch.Click += LaunchButton_OnClick; buttonLaunch.Visibility = Android.Views.ViewStates.Invisible; textMessages = FindViewById <TextView>(Resource.Id.textViewDevice); TextView text = FindViewById <TextView>(Resource.Id.textViewDevice); text.Text = "Touch Tag to Device"; //StartActivityForResult(intent, (int)ActivityCode.NFCPair); nfcAdapter = NfcAdapter.GetDefaultAdapter(this); NFCPairLib.NewInstance(this.ApplicationContext, this, 0); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.nfc_utils_fragment); // get the buttons _readTagButton = FindViewById <Button>(Resource.Id.read_tag_button); _writeTagButton = FindViewById <Button>(Resource.Id.write_tag_button); // assign the click events _readTagButton.Click += ReadTagButton_OnClick; _writeTagButton.Click += WriteTagButton_OnClick; _messageTextView = FindViewById <TextView>(Resource.Id.text_view); _writeTextView = FindViewById <TextView>(Resource.Id.write_text); _nfcAdapter = NfcAdapter.GetDefaultAdapter(this); //var fragmentTransaction = FragmentManager.BeginTransaction(); //fragmentTransaction.Replace(Android.Resource.Id.Content, nfcUtils); //fragmentTransaction.Commit(); }
public NFCMessage OnPause() { if (!Init) { return(NFCMessage.NFC_NOT_INITIALIZED); } else if (NfcAdapter == null) { return(NFCMessage.NFC_NOT_AVAILABLE); } else if (!NfcAdapter.IsEnabled) { return(NFCMessage.NFC_DISABLED); } else { NfcAdapter.DisableForegroundDispatch(_act); return(NFCMessage.NFC_NO_ERROR); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.attend_layout); token = Intent.Extras.GetString("token"); _nfcAdapter = NfcAdapter.GetDefaultAdapter(this); if (_nfcAdapter == null) { Intent intent = new Intent(this, typeof(NoNFCActivity)); StartActivity(intent); } else { NfcAdapter adapter = NfcAdapter.GetDefaultAdapter(this); adapter.SetNdefPushMessageCallback(this, this); adapter.SetOnNdefPushCompleteCallback(this, this); } }
protected override void OnCreate(Bundle savedInstanceState) { UserDialogs.Init(this); TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; global::Xamarin.Forms.Forms.Init(this, savedInstanceState); 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; base.OnCreate(savedInstanceState); UserDialogs.Init(this); LoadApplication(new App()); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); // Get a reference to the default NFC adapter for this device. This adapter // is how an Android application will interact with the actual hardware. _nfcAdapter = NfcAdapter.GetDefaultAdapter(this); _writeTagButton = FindViewById <Button>(Resource.Id.write_tag_button); _writeTagButton.Click += WriteTagButtonOnClick; _readTagButton = FindViewById <Button>(Resource.Id.read_tag_button); _readTagButton.Click += ReadTagButtonOnClick; _textView = FindViewById <TextView>(Resource.Id.text_view); _inputText = FindViewById <EditText>(Resource.Id.input_text); _inputText.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => { nfcdata = e.Text.ToString(); }; String ssid = getWifiInfo(); DisplayMessage(ssid); }
/* * learning from * http://blog.csdn.net/earbao/article/details/50961713 */ protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.ScanButton); button.Click += Scan;; var writerButton = FindViewById <Button>(Resource.Id.WriteButton); writerButton.Click += Write; var label = FindViewById <TextView>(Resource.Id.ResultLabel); nfcAdapter = NfcAdapter.GetDefaultAdapter(ApplicationContext); if (nfcAdapter == null) { label.Text = "NFC is not available."; return; } if (!nfcAdapter.IsEnabled) { label.Text = "NFC is disabled."; return; } //nfcAdapter.SetNdefPushMessageCallback(this, this); var intent = new Intent(this, this.Class); intent.AddFlags(ActivityFlags.SingleTop); nfcPi = PendingIntent.GetActivity(this, 0, intent, 0); nfcFilter = new IntentFilter(NfcAdapter.ActionNdefDiscovered); nfcFilter.AddCategory(Intent.CategoryDefault); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.SetContentView(Resource.Layout.Main); mInfoText = FindViewById <TextView> (Resource.Id.textView); // Check for available NFC Adapter mNfcAdapter = NfcAdapter.GetDefaultAdapter(this); if (mNfcAdapter == null) { mInfoText = FindViewById <TextView> (Resource.Id.textView); mInfoText.Text = "NFC is not available on this device."; } else { // Register callback to set NDEF message mNfcAdapter.SetNdefPushMessageCallback(this, this); // Register callback to listen for message-sent success mNfcAdapter.SetOnNdefPushCompleteCallback(this, this); } }
public static void SetupForegroundDispatch(Activity activity, NfcAdapter adapter) { Intent intent = new Intent(activity.ApplicationContext, activity.GetType()); intent.SetFlags(ActivityFlags.SingleTop); PendingIntent pendingIntent = PendingIntent.GetActivity(activity.ApplicationContext, 0, intent, 0); IntentFilter[] filters = new IntentFilter[1]; string[][] techList = new string[][] { }; // Notice that this is the same filter as in our manifest. filters[0] = new IntentFilter(); filters[0].AddAction(NfcAdapter.ActionNdefDiscovered); filters[0].AddCategory(Intent.CategoryDefault); try { filters[0].AddDataType(StringConstants.MimeType); } catch (Android.Content.IntentFilter.MalformedMimeTypeException) { throw new RuntimeException("Check your mime type."); } adapter.EnableForegroundDispatch(activity, pendingIntent, filters, techList); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.Inflate(Resource.Layout.fragment_scan_tag, container, false); Button clearButton = view.FindViewById <Button>(Resource.Id.clearButton); clearButton.Click += ClearButton_Click; var nfcAdapter = NfcAdapter.GetDefaultAdapter(MainActivity.Instance); var mainTextView = view.FindViewById <TextView>(Resource.Id.mainTextView); if (nfcAdapter == null) { mainTextView.Text = "No NFC Adapter found!"; } else if (!nfcAdapter.IsEnabled) { mainTextView.Text = "NFC Adapter is disabled!"; } return(view); }
protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); _nfc_avaible = false; _do_scanning = false; _nfc_adapter = NfcAdapter.GetDefaultAdapter(this); if (_nfc_adapter != null) { _nfc_avaible = true; _pending_intent = PendingIntent.GetActivity(this, 0, new Intent(this, GetType()).AddFlags(ActivityFlags.SingleTop), 0); _filters = new IntentFilter[] { new IntentFilter(NfcAdapter.ActionTagDiscovered) }; } Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App()); }
public IObservable <NDefRecord[]> Reader() => Observable.Create <NDefRecord[]>(ob => { var adapter = NfcAdapter.GetDefaultAdapter(this.context.AppContext); adapter.EnableReaderMode( this.context.CurrentActivity, this, NfcReaderFlags.NfcA | NfcReaderFlags.NfcB | NfcReaderFlags.NfcBarcode | NfcReaderFlags.NfcF | NfcReaderFlags.NfcV | NfcReaderFlags.NoPlatformSounds, new Android.OS.Bundle() ); var sub = this.recordSubj.Subscribe(ob.OnNext); return(() => { adapter.DisableReaderMode(this.context.CurrentActivity); sub.Dispose(); }); });
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); txtStatus = (TextView)FindViewById(Resource.Id.txtStatus); btnGetSAMInfo = (Button)FindViewById(Resource.Id.btnGetSAMInfo); btnGetSAMInfo.Click += onClickGetSAMInfo; getVersionAPDUs.Add(SAMType.Mifare, new byte[] { (byte)0x80, (byte)0x60, (byte)0x00, (byte)0x00, /*(byte)0x00,*/ (byte)0x00 }); getVersionAPDUs.Add(SAMType.Felica, new byte[] { (byte)0xA0, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x05, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xE6, (byte)0x00, (byte)0x00 }); nfcAdapter = NfcAdapter.GetDefaultAdapter(this); if (nfcAdapter == null) { Toast.MakeText(this, GetString(Resource.String.message_nfc_not_supported), ToastLength.Long).Show(); Finish(); return; } nfcIntent = PendingIntent.GetActivity(this, 0, new Intent(this, this.Class) .AddFlags(ActivityFlags.SingleTop), 0); //The EMDKManager object will be created and returned in the callback. EMDKResults results = EMDKManager.GetEMDKManager(Application.Context, this); //Check the return status of EMDKManager object creation. if (results.StatusCode == EMDKResults.STATUS_CODE.Success) { //EMDKManager object creation success } else { //EMDKManager object creation failed } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); StatusBarTintHelper.SetStatusBarColor(this); //// Create your application here SetContentView(Resource.Layout.settings_board_activity); llRootView = FindViewById <LinearLayout>(Resource.Id.llRootView); FindViewById <LinearLayout>(Resource.Id.llStatusBarStub).LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, StatusBarTintHelper.GetStatusBarHeight()); toolbar = FindViewById <Toolbar>(Resource.Id.toolbar_actionbar); SetSupportActionBar(toolbar); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetDisplayShowHomeEnabled(true); SupportActionBar.SetHomeButtonEnabled(true); wvContent = FindViewById <WebView>(Resource.Id.wvContent); wvContent.Settings.JavaScriptEnabled = true; wvContent.AddJavascriptInterface(this, "wst"); var HtmlTemplate = ""; using (var sr = new StreamReader(MainApp.ThisApp.Assets.Open("wst.html"))) { HtmlTemplate = sr.ReadToEnd(); } wvContent.LoadDataWithBaseURL( "file:///android_asset/html/", HtmlTemplate, "text/html", "utf-8", null); _nfcAdapter = NfcAdapter.GetDefaultAdapter(this); }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); NfcManager NfcManager = (NfcManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.NfcService); NFCdevice = NfcManager.DefaultAdapter; Xamarin.Forms.DependencyService.Register <INfc, NfcForms>(); x = Xamarin.Forms.DependencyService.Get <INfc>() as NfcForms; if (NFCdevice == null) { var alert = new AlertDialog.Builder(this).Create(); alert.SetMessage("NFC is not supported on this device."); alert.SetTitle("NFC Unavailable"); alert.SetButton("exit", CancelButtonOnClick); alert.SetCanceledOnTouchOutside(false); alert.Show(); } else { if (!NFCdevice.IsEnabled) { var alert = new AlertDialog.Builder(this).Create(); alert.SetMessage("NFC is currently off."); alert.SetTitle("Please enable NFC to use this app."); alert.Show(); } } telephonyManager = (TelephonyManager)GetSystemService(TelephonyService); IMEINumber = telephonyManager.Imei; Settings.IMEI = IMEINumber; LoadApplication(new App()); }
public NFCMessage OnResume() { if (!Init) { return(NFCMessage.NFC_NOT_INITIALIZED); } else if (NfcAdapter == null) { return(NFCMessage.NFC_NOT_AVAILABLE); } else if (!NfcAdapter.IsEnabled) { return(NFCMessage.NFC_DISABLED); } else { var filters = Actions.Select(s => new IntentFilter(s)).ToArray(); var intent = new Intent(_act, _act.GetType()).AddFlags(ActivityFlags.SingleTop); var pendingIntent = PendingIntent.GetActivity(_act, 0, intent, 0); NfcAdapter.EnableForegroundDispatch(_act, pendingIntent, filters, null); return(NFCMessage.NFC_NO_ERROR); } }
protected override void OnCreate(Bundle savedInstanceState) { Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MjMyNTM4QDMxMzgyZTMxMmUzMGk5SnZMR3JhaWRBSzY0cEFCaDhQVGI0WDQ2ZDcrbTVYQVJWMmRyR0dybjA9"); TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental"); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // CrossNFC.Init(this); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); Xamarin.FormsMaps.Init(this, savedInstanceState); CachedImageRenderer.Init(true); global::Xamarin.Auth.Presenters.XamarinAndroid.AuthenticationConfiguration.Init(this, savedInstanceState); LoadApplication(new App()); _nfcAdapter = NfcAdapter.GetDefaultAdapter(this); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.KeyGen); text = FindViewById <TextView>(Resource.Id.textView1); progBar = FindViewById <ProgressBar>(Resource.Id.progBar); finishedGen = FindViewById <Button>(Resource.Id.button1); startGen = FindViewById <Button>(Resource.Id.button2); pm = new PadManager(GetExternalFilesDir(null).ToString()); keys = new System.Collections.Generic.List <string>(); SetProgressBarIndeterminate(false); progBar.Progress = 0; progBar.Max = 100; finishedGen.Enabled = false; startGen.Click += StartGen_Click; finishedGen.Click += StartNfc_Click; _nfcAdapter = NfcAdapter.GetDefaultAdapter(this); if (_nfcAdapter == null) { text.Text = "NFC not available"; } if (pm == null) { text.Text = "Pad manager is null"; } // Get the contact name passed in through the intent when ViewContactActivity launches this intent contactName = Intent.GetStringExtra("contactName"); // stored in key "contactName" Identity.LoadUsername(GetExternalFilesDir(null).ToString()); myName = Identity.Username; text.Text = contactName; }
/// <summary> /// /// </summary> public void EnableWriteMode() { // Create an intent filter for when an NFC tag is discovered. When // the NFC tag is discovered, Android will u var tagDetected = new IntentFilter(NfcAdapter.ActionTagDiscovered); var filters = new[] { tagDetected }; // When an NFC tag is detected, Android will use the PendingIntent to come back to this activity. // The OnNewIntent method will invoked by Android. var intent = new Intent(this, GetType()).AddFlags(ActivityFlags.SingleTop); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0); if (NfcAdapter == null) { var alert = new Android.App.AlertDialog.Builder(this).Create(); alert.SetMessage("NFC is not supported on this device."); alert.SetTitle("NFC Unavailable"); alert.Show(); } else { NfcAdapter.EnableForegroundDispatch(this, pendingIntent, filters, null); } }
protected override void OnCreate(Bundle savedInstanceState) { CrossNFC.Init(this); base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.login); ComponentLocalizer(); ActionHooker(); NfcAdapter nfcAdapter = NfcAdapter.GetDefaultAdapter(this); if (nfcAdapter == null) { Android.Support.V7.App.AlertDialog.Builder alertDialog = new Android.Support.V7.App.AlertDialog.Builder(this); alertDialog.SetTitle(GetString(Resource.String.noNFC)); alertDialog.SetIcon(Resource.Drawable.ic1c_192x192); alertDialog.SetMessage(GetString(Resource.String.noSupport)); alertDialog.SetCancelable(false); alertDialog.SetNeutralButton(GetString(Resource.String.exit), delegate { Finish(); }); alertDialog.Show(); } CreateNotificationChannel(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.menuNFC); // Create your application here editMensagemPadrao = FindViewById <EditText>(Resource.Id.editMensagemPadrao); btn_formatarCartao = FindViewById <Button>(Resource.Id.btn_formatarCartao); btn_gravar = FindViewById <Button>(Resource.Id.btn_gravar); btn_ler = FindViewById <Button>(Resource.Id.btn_leitura); btn_teste = FindViewById <Button>(Resource.Id.btn_teste); mNfcAdapter = NfcAdapter.GetDefaultAdapter(this); painel_nfc = FindViewById <LinearLayout>(Resource.Id.painel_nfc); painel_nfc.Visibility = ViewStates.Invisible; painel_nfc_resposta = FindViewById <TextView>(Resource.Id.response); initViews(); InitNFC(); }
private void InitNFC() { mNfcAdapter = NfcAdapter.GetDefaultAdapter(this); }
private int isOK = 0; //收发货标识 #endregion #region 创建Activity protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.InsideDish); //操作人 UserName = Intent.GetStringExtra("username"); username = FindViewById <EditText>(Resource.Id.username); username.Text = UserName; btGet = FindViewById <ToggleButton>(Resource.Id.btGet); btGet.Enabled = false; btGet.Click += getDb; btSender = FindViewById <ToggleButton>(Resource.Id.btSet); btSender.Enabled = false; btSender.Click += sendDb; btSave = FindViewById <ToggleButton>(Resource.Id.btSave); btSave.Enabled = true; btSave.Checked = true; btSave.Click += dbSave; if (CommonFunction.mode == "NFC") { #region NFC 模式 try { m_nfcAdapter = NfcAdapter.GetDefaultAdapter(this); if (m_nfcAdapter == null) { CommonFunction.ShowMessage("设备不支持NFC!", this, true); return; } if (!m_nfcAdapter.IsEnabled) { CommonFunction.ShowMessage("请在系统设置中先启用NFC功能!", this, true); return; } //m_nfcAdapter.SetNdefPushMessage(CreateNdefMessageCallback(), this, this); mTechLists = new string[][] { new string[] { "Android.Nfc.Tech.MifareClassic" }, new string[] { "Android.Nfc.Tech.NfcA" } }; IntentFilter tech = new IntentFilter(NfcAdapter.ActionTechDiscovered); mFilters = new IntentFilter[] { tech, }; //存放支持technologies的数组 mPendingIntent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(InsideDish)).AddFlags(ActivityFlags.SingleTop), PendingIntentFlags.UpdateCurrent); //intent过滤器,过滤类型为NDEF_DISCOVERED //Mifare卡和Desfare卡都是ISO - 14443 - A卡 ProcessAdapterAction(this.Intent); } catch (Exception ex) { CommonFunction.ShowMessage(ex.Message, this, true); } #endregion } else if (CommonFunction.mode == "SerialPort") { #region SerialPort模式 try { Stream im; Stream om; serial = new SerialPort(13, 115200, 0); serial.Power_5Von(); im = serial.MFileInputStream; om = serial.MFileOutputStream; hf = new HfReader(im, om); } catch (Exception ex) { CommonFunction.ShowMessage(ex.Message, this, true); } #endregion } }
public static void StopForegroundDispatch(Activity activity, NfcAdapter adapter) { adapter.DisableForegroundDispatch(activity); }
public NfcService() { var activity = CrossCurrentActivity.Current.Activity; _nfcDevice = NfcAdapter.GetDefaultAdapter(activity); }
protected override void OnStart() { base.OnStart(); nfcAdapter = NfcAdapter.GetDefaultAdapter(this); }
static void Main(string[] args) { try { Console.WriteLine(string.Format("GoToTags NFC Sample App v{0}", Assembly.GetCallingAssembly().GetName().Version.ToString())); Console.WriteLine(); Licensing.Unlock("unlock code goes here"); Console.WriteLine(string.Format("Licensed to: {0}", Licensing.GetLicenseData())); Console.WriteLine(); Console.WriteLine("Place an nfc tag on the reader; press 'Enter' when ready."); Console.ReadLine(); Console.WriteLine(); try { var isCertPropSvcRunning = CertPropSvc.IsRunning(); if (isCertPropSvcRunning) { Console.WriteLine("The CertPropSvc Service is running; it interferes with NFC and should be stopped."); CertPropSvc.StopService(); Console.WriteLine("The CertPropSvc service was stopped."); Console.WriteLine(); } else { Console.WriteLine("The CertPropSvc service is not running."); Console.WriteLine(); } } catch (Exception) { // trap exceptions here, some systems dont have this service } nfcAdapter = NfcAdapter.DefaultAdapter; if (nfcAdapter == null) { Console.WriteLine("No nfc readers found"); goto done; } // get all of the readers Console.WriteLine("Supported Nfc readers:"); var readers = nfcAdapter.SupportedReaders(); if (readers.Count() > 0) { readers.ToList().ForEach(r => Console.WriteLine(r.ToString())); Console.WriteLine(); } else { Console.WriteLine("No nfc readers found"); goto done; } // use the first reader var reader = readers.First(); NfcAdapter.Adapter(reader); // get the tag var tag = nfcAdapter.GetTag(); if (tag == null) { Console.WriteLine("An nfc tag is not on the reader."); Console.WriteLine(); } else { var tagTech = tag.TagType; Console.WriteLine(string.Format("Tag Tech: {0}", tagTech)); // ndef operations using (var ndef = NdefTechnology.Get(tag)) { ndef.Connect(); var isFormatted = ndef.IsFormatted; Console.WriteLine(string.Format("Is Formatted: {0}", isFormatted)); var isWritable = ndef.IsWritable; Console.WriteLine(string.Format("Is Writable: {0}", isWritable)); var tagUID = ndef.TagUIDString(); Console.WriteLine(string.Format("Tag UID: {0}", tagUID)); Console.WriteLine(); Console.WriteLine("Ndef Records:"); var message = ndef.GetNdefMessage(); if (message != null) { foreach (var record in message.Records) { Console.WriteLine(string.Format("{0} {1}", record.GetType().Name, record.ToString())); } Console.WriteLine(); } if (isWritable) { ndef.Erase(); Console.WriteLine("The tag's contents have been erased."); Console.WriteLine(); // encode an ndef url to the nfc tag var nfcUriRecord = new NfcUriRecord("http://www.buynfctags.com"); ndef.WriteNdefMessage(nfcUriRecord); Console.WriteLine("The tag has been encoded with the url: {0}", nfcUriRecord.Uri); Console.WriteLine(); // this will make the tag permanently read only //ndef.MakeReadOnly(); } } } Console.WriteLine("Place nfc tags on the reader, one after another..."); // listen to the status changed event to listen for tags places on the reader nfcAdapter.StatusChanged += nfcAdapter_StatusChanged; // will read 3 tags, then quit while (tagCounter < 3) { Thread.Sleep(100); } // give the last tag a bit of time to be read Thread.Sleep(100); Console.WriteLine("Done!"); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.ToString()); Console.ResetColor(); } done: Console.WriteLine(); Console.WriteLine("Press 'Enter' to quit"); Console.ReadLine(); }
public void UseNfcReader(string reader) { this.NfcAdapter = NfcAdapter.Adapter(reader); }
public void Dispose() { try { if (this.NfcAdapter != null) this.NfcAdapter.Dispose(); } catch (Exception) { } finally { this.NfcAdapter = null; this.PlatformClient = null; } }