|
I bought a Nokia lumia 930 mobile phone a while ago, and in the past few days I learned that there is a tall function called NFC, which can read bank cards, all-in-one cards and other information. I put my bank card on my phone, and the phone beeped, but nothing was shown. Baidu suddenly found that only Alipay wallets on Android have this function, so it researched and wrote a small program. As shown below
This program is very simple, the bank card will output "the bank card is coming" when it is pasted on the mobile phone, and the "bank card is gone" when it leaves. The implementation process is simple and follows:
Create an empty windows phone project and add three class members and two event functions to the MainPage. [mw_shl_code=csharp,true] Windows::Foundation::EventRegistrationToken m_arrivedToken;
Windows::Foundation::EventRegistrationToken m_departedToken;
Windows::Networking::Proximity::ProximityDevice^ m_proximityDevice;
void DeviceArrived(Windows::Networking::Proximity::ProximityDevice^ device); void DeviceDeparted(Windows::Networking::Proximity::ProximityDevice^ device); [/mw_shl_code]
Then get the default NFC device in the constructor of MainPage, register two events in OnNavigatedTo, which are used to respond to the event of the bank card approaching the mobile phone and leaving, so that when the event is triggered, the DeviceArrived and DeviceDeparted processes will be called, and the process will simply execute an output log. over
[mw_shl_code=csharp,true] MainPage::MainPage()
{ InitializeComponent(); m_proximityDevice = ProximityDevice::GetDefault();
}
void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
{ (void) e; Unused parameters if (this->m_proximityDevice)
{ m_arrivedToken = m_proximityDevice->DeviceArrived += ref new DeviceArrivedEventHandler(this, &MainPage::DeviceArrived, CallbackContext::Same); m_departedToken = m_proximityDevice->DeviceDeparted += ref new DeviceDepartedEventHandler(this, &MainPage::DeviceDeparted, CallbackContext::Same);
}
}
void MainPage::DeviceArrived(ProximityDevice^ device)
{ ErrorText->Text += "The bank card is coming! \r\n”;
}
void MainPage::DeviceDeparted(ProximityDevice^ device)
{ ErrorText->Text += "The bank card is gone! \r\n”; }[/mw_shl_code]
In this way, such a program is completed, and the next step is to read the information. . .
If you have time, continue to study it again and read out the bank card data.
|