大佬教程收集整理的这篇文章主要介绍了有没有办法将 NDEF 消息传递给字符串?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我有一个存储 URL 的 NFC 标签,我正在构建一个 AndroID 应用程序,该应用程序读取该标签并将应用程序启动到主活动。之后,我有一个显示该网站的 WebVIEw。我的问题是,每个标签都有不同的网址/路径(假设它们是服装项目,每个标签都指向网站上的一个产品)。如何从标签(url)获取 NDEF 消息并将其传递给 webvIEw 的该参数?感谢您的帮助,我将在这里留下我的代码。
我遵循了 NFC 上的 androID 文档,基本的和高级的,用谷歌搜索了每一页并在 reddit 上搜索了所有内容,但是我找不到任何答案......
这是我的主要活动,读取标签后立即打开的活动:
class MainActivity : AppCompatActivity() {
private var adapter: NfcAdapter? = null
// Pending intent for NFc intent foreground dispatch.
// Used to read all NDEF Tags while the app is running in the foreground.
private var nfcPendingIntent: PendingIntent? = null
// Optional: filter NDEF Tags this app receives through the pending intent.
//private var nfcIntentFilters: Array<IntentFilter>? = null
private val KEY_LOG_TEXT = "logText"
overrIDe fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceStatE)
setContentVIEw(R.layout.activity_main)
initNfcAdapter()
if (intent != null)
{
processIntent(intent)
}
}
private fun initNfcAdapter() {
val nfcManager = getSystemservice(Context.NFC_serviCE) as NfcManager
adapter = nfcManager.defaultAdapter
}
overrIDe fun onResume() {
super.onResume()
enableNfcForegrounddispatch()
}
private fun enableNfcForegrounddispatch() {
try {
val intent = Intent(this,javaClass).addFlags(Intent.FLAG_ACTIVITY_SINGLE_top)
val nfcPendingIntent = PendingIntent.getActivity(this,intent,0)
adapter?.enableForegrounddispatch(this,nfcPendingIntent,null,null)
} catch (ex: IllegalStateException) {
}
}
overrIDe fun onPause() {
disableNfcForegrounddispatch()
super.onPause()
}
private fun disableNfcForegrounddispatch() {
try {
adapter?.disableForegrounddispatch(this)
} catch (ex: IllegalStateException) {
}
}
private fun processIntent(checkIntent: Intent) {
if(checkIntent.action == NfcAdapter.ACTION_NDEF_disCOVERED) {
val raw@R_874_8798@ges = checkIntent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_@R_874_8798@GES)
}
}
}
这是 webvIEw 活动:
class WebvIEw : AppCompatActivity() {
private lateinit var webvIEw: WebvIEw1
overrIDe fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceStatE)
setContentVIEw(R.layout.activity_webvIEw)
val myWebVIEw: WebVIEw = findVIEwByID(R.ID.webvIEw)
myWebVIEw.webVIEwClIEnt = object : WebVIEwClIEnt () {
overrIDe fun shouldOverrIDeUrlLoading(vIEw: WebVIEw?,url: String?): Boolean {
if (url != null) {
vIEw?.loadUrl(url)
}
return true
}
}
myWebVIEw.loadUrl("https://website.com")
myWebVIEw.setTings.JavaScriptEnabled=true
myWebVIEw.setTings.allowContentAccess=true
myWebVIEw.setTings.domStorageEnabled=true
myWebVIEw.setTingS.UseWIDeVIEwPort=true
myWebVIEw.setTings.setAppCacheEnabled(true)
}
}
我想将 NDEF 消息传递给 myWebVIEw.loadUrl()。
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的有没有办法将 NDEF 消息传递给字符串?全部内容,希望文章能够帮你解决有没有办法将 NDEF 消息传递给字符串?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。