html5 调用 nfc,Can HTML5 access NFC chips on mobile phones

这篇博客探讨了如何在HTML5中访问移动设备的NFC芯片。虽然HTML5规范本身不直接支持NFC,但可以通过如PhoneGap这样的移动框架实现。作者提到PhoneGap计划支持NFC,但目前没有明确的时间线。一种解决方案是使用HTML5构建UI,并在原生应用内嵌WebView,通过原生应用访问NFC功能并传递数据到WebApp。另外,还提到了ChariotSolutions的PhoneGap NFC插件作为集成NFC功能的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题

I'm not too familiar with HTML5 so does anyone know if HTML5 will be able to access NFC chips built into mobile devices? Or, can someone suggest another way to do this using some other method? My goal is to produce a cross platform HTML5 web app that can access NFC functionality on NFC equipped phones. I have looked into mobile frameworks like PhoneGap but although they have NFC on their roadmap, they do not have any timelines nor implementation details to offer.

Thanks.

回答1:

NFC access via some proprietary framework may be possible, but I don't think it's currently built into the HTML 5 spec itself.

PhoneGap uses HTML5 for the main UI of the mobile application, and then takes specific code that you write (javascript API I think), which is then translated into native code for each of the mobile devices it is ported to. So, one option you have is building your main UI in HTML5, and then displaying that in a WebView or equivalent inside a native application, then accessing NFC specific features via the native application and passing it to your webapp via a dynamic URL like http://mysampleapp.com/NFC/somestringofdatafromthenfcthatiwillparsetouseinmyhtml5app

回答2:

If you are using Phonegap 3.0 and the Cordova CLI you can easily integrate RFID reading capabilities through NFC by using Chariot Solutions Phonegap NFC plugin from Github and following the steps laid out by Øystein Heimark/Dogu in the referenced blog post.

Github: Github repository

Blog:

ADDING RFID CAPABILITIES TO YOUR ANDROID PHONEGAP APPLICATION

来源:https://stackoverflow.com/questions/5668647/can-html5-access-nfc-chips-on-mobile-phones

### NFC Counter Implementation in Mobile Applications In mobile applications and devices, Near Field Communication (NFC) technology can be utilized to implement a counter function effectively. This functionality allows for tracking interactions between two NFC-enabled devices or tags. #### Using NFC Tags as Counters One common approach involves using programmable NFC tags that store data such as counters. When an application reads from these tags, it increments the stored value by one each time interaction occurs. The process typically includes: - Reading current count value from tag memory. - Incrementing this number within app logic. - Writing updated count back onto the same location of the tag. This method leverages simple read/write operations supported natively across most modern smartphones equipped with Android OS or iOS platforms[^1]. ```java // Java code snippet demonstrating basic NFC counter operation public void incrementCounter(NdefndefTag){ NdefRecord[] records = ndefTag.getRecords(); String existingCountStr = new String(records[0].getPayload()); int currentCount = Integer.parseInt(existingCountStr); // Increment count int newCount = currentCount + 1; // Prepare record payload containing incremented integer converted into byte array byte[] newDataBytes = String.valueOf(newCount).getBytes(Charset.forName("US-ASCII")); NdefRecord updatedRecord = new NdefRecord( NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, null, newDataBytes); // Write changes back to tag NdefMessage messageToUpdate = new NdefMessage(updatedRecord); ndefTag.writeNdefMessage(messageToUpdate); } ``` For security purposes, developers should consider implementing measures like encryption before writing sensitive information onto public-accessible NFC chips[^2]. #### Integration Within Apps Applications may also maintain internal counters synchronized through cloud services whenever users tap their phones against specific points-of-interest marked by static NFC stickers placed strategically around physical spaces. Such setups enable seamless integration without requiring constant internet connectivity while still providing robustness against tampering attempts due to localized storage mechanisms employed at endpoints.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值