首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NFC标签意图过滤

NFC标签意图过滤
EN

Stack Overflow用户
提问于 2021-02-10 04:00:41
回答 1查看 21关注 0票数 0

我的实现目标: Nt3h2211标签(通过I2C从PIC-mcu配置),然后由我的Android应用程序读取。

How to launch app by scanning NDEF NFC tag?这个帖子看起来和我遇到的问题非常接近。根据这些建议编辑清单意图过滤器并不能解决我的问题。任何帮助都是非常感谢的。

我完成了硬件实现并编写了PIC固件;因此,如果需要,我可以更改标记配置。标签被格式化为NDEF,并且有效载荷仅为位字段…此时,只填充了16个字节。请参阅从制造商的NFC标签读取实用程序读取的标签存储器状态的图片。

Tag configuration

清单文件nfc意图筛选器:

代码语言:javascript
复制
    <intent-filter>
    <action android:name=”android.nfc.action.NDEF.DISCOVERED”/>
    <category android:name=”android.intent.category.DEFAULT”/>
    <data android:scheme=”vnd.android.nfc”
              android:host=”ext”
              android:pathPrefix=”/blackfeathersystems.com:pr”/>
</intent-filter>
<intent-filter>
    <action android:name=”android.nfc.action.TECH.DISCOVERED”/>
    <category android:name=”android.intent.category.DEFAULT”/>
    <data android:scheme=”vnd.android.nfc”
              android:host=”ext”
              android:pathPrefix=”/blackfeathersystems.com:pr”/>
</intent-filter>
<meta-data android:name=”android.nfc.action.TECH_DISCOVERED”
                   android:resource=”@xml/nfc_tech_list” />

nfc_tech_list xml文件内容:

代码语言:javascript
复制
<?xml version=”1.0” endoding=”utf-8”?>
<resources xmlns:xliff=”urn:oasis:names:tc:xliff:document:1.2”>
    <tech-list>
    <tech> android.nfc.tech.NfcA</tech>
    </tech-list>
    <tech-list>
    <tech> android.nfc.tech.Ndef</tech>
    </tech-list>
    <tech-list>
    <tech> android.nfc.tech.MifareClassic</tech>
    </tech-list>
    <tech-list>
    <tech> android.nfc.tech.MifareUltralight</tech>
    </tech-list>
</resources>

主要活动代码。请注意,为了简洁起见,onNewIntent()函数已经被Toast的函数去掉了--但它只解析为“action: NOT DISCOVERED”。

代码语言:javascript
复制
package com.example.nfc2211comms2

class MainActivity : AppCompatActivity() {

lateinit var nfcAdapter : NfcAdapter
lateinit var pendingIntent: PendingIntent
lateinit var nfcA: NfcA

    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.main_fragment)

    nfcAdapter = NfcAdapter.getDefaultAdapter(this)
    
} // end onCreate

    override fun onResume() {
        Val intent = Intent(this, javaClass).apply {
        addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
}

pendingIntent = PendingIntent.getActivity(this, 0, intent, 0)

nfcAdapter.enableForegroundDispatch(this, pendingIntent, null, null)

onNewIntent(intent)

} // end onResume


    override fun onNewIntent(nintent: Intent) {
    super.onNewIntent(intent)

    if (NfcAdapter.ACTION_NDEF_DISCOVERED == nintent.action) {
Toast.makeText(this, “ action: NDEF ”, LENGTH_SHORT).show()
} else if (NfcAdapter.ACTION_TECH_DISCOVERED == nintent.action) {
Toast.makeText(this, “ action: TECH ”, LENGTH_SHORT).show()
} else {
Toast.makeText(this, “ Not Discovered ”, LENGTH_SHORT).show()
}
} // end onNewIntent

override fun onPause() {
    super.onPause()
    nfcA.close()
    nfcAdapter.disableForegroundDispatch(this)
}

override fun onDestroy() {
    super.onDestroy()
    finish()
}

} // end mainActivity
EN

回答 1

Stack Overflow用户

发布于 2021-03-03 23:49:55

我想我可能已经回答了自己的问题,至少部分回答了。在重写代码以减少冗长之后,我发现NDEF格式的标签需要三个第一个记录中的一个:

  1. SMART POSTER,2)知名MIME或3) URI

我有外部的,所以NDEF_DISCOVERED过滤器永远不会被击中。因此,TECH_DISCOVERED意图确实起作用了。

谢谢!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66126237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档