简体   繁体   English

如何管理NFC标签到多个应用程序的传递

[英]How to manage delivery of NFC tags to multiple apps

I want to create an app that stores a timestamp into the database when I scan my work-batch which contains an NFC tag. 我想创建一个在扫描包含NFC标签的工作批时将时间戳存储到数据库中的应用。 This will be done via an IntentService without starting an activity. 这将通过IntentService完成,而无需启动活动。 After a second scan another timestamp will be stored into the database via the IntentService. 在第二次扫描后,另一个时间戳将通过IntentService存储到数据库中。 No activity has to be started. 无需开始任何活动。 A notification will be enough. 一个通知就足够了。 The activity can be started manually by the user to see the info. 该活动可以由用户手动启动以查看信息。

I have read that there are a lot of different tag technologies. 我读到有很多不同的标签技术。 But I like to make my app a bit more universal. 但是我想让我的应用程序更具通用性。 So I don't know which kind of NFC tags my clients are going to use. 因此,我不知道我的客户将使用哪种NFC标签。 I could listen for all the different tags and let the user pair a tag with a certain task. 我可以收听所有不同的标签,并让用户将标签与特定任务配对。

This is fine unless there is one NFC app on the phone. 除非手机上只有一个NFC应用程序,否则可以。 But I have another app which uses NFC. 但是我还有另一个使用NFC的应用程序。 And when I scan a tag Android shows me a selection dialog which app may handle the tag. 当我扫描标签时,Android会向我显示一个选择对话框,该应用可以处理该标签。 But I don't want this every time I scan a tag. 但是我不希望每次扫描标签时都这样。 I want to use both apps so I dont select a default for the tags. 我想同时使用这两个应用程序,所以我不为标签选择默认值。

So the question is, How can I scan a tag and route it to the right app. 因此,问题是,如何扫描标签并将其路由到正确的应用程序。 So tag A will be handled by app A and tag B by app B without getting the selection box every time. 因此,标签A将由应用A处理,标签B由应用B处理,而无需每次都获得选择框。

I was thinking what the best option should be or maybe somebody has a great idea how to solve this. 我在想最好的选择应该是什么,或者也许有人对如何解决这个问题有个好主意。

I have taught of a couple of different solutions: 我教过几种不同的解决方案:

  1. Use only writable NDEF tags and add a Android Application Record (AAR) to it. 仅使用可写的NDEF标签,并向其添加Android应用程序记录(AAR)。 So it will launch the right application after scanning. 因此,它将在扫描后启动正确的应用程序。 (If there is no NFC app active in the foreground) this will mean that the user is restricted to a tag technology and needs to write it before using. (如果前台没有处于活动状态的NFC应用),这意味着用户只能使用标签技术,需要在使用前编写标签技术。

  2. Let the application listen for all NFC tags and if a tag is not paired to a task forward it to the system again so that other apps can handle it. 让应用程序监听所有NFC标签,如果没有将标签与任务配对,则将其再次转发给系统,以便其他应用程序可以处理它。 (Don't know if this is possible) (不知道这是否可能)

  3. Write a app which listens for all NFC tags and let the user decide which tag will be send to which application. 编写一个监听所有NFC标签的应用程序,让用户决定将哪个标签发送到哪个应用程序。 So when a new tag is received by the application it asks the user which app may handle the tag and stores the default for this specific tag [by ID or something] into a database. 因此,当应用程序接收到新标签时,它会询问用户哪个应用程序可以处理该标签,并将此特定标签的默认值(通过ID或其他方式)存储到数据库中。 So the next time it will route the intent to the default application for this tag. 因此,下一次它将此意图路由到该标签的默认应用程序。 (Or is there already something like this?) (或者已经有这样的东西了?)

Hopefully this question is a bit clear. 希望这个问题有点清楚。 Else I'll try to clarify it a bit more if you like ;-) 否则,如果您愿意,我会尝试澄清更多;-)

I really like to hear what you think about this. 我真的很想听听您对此的看法。 Or maybe you have some good suggestions? 也许您有一些好的建议? Please let me know. 请告诉我。

Thanks in advance. 提前致谢。

I've successfully use an application specific URL scheme for this. 我已经为此成功使用了特定于应用程序的URL方案。 Let's assume your URL scheme is "kuiperstimestamp". 假设您的URL方案是“ kuiperstimestamp”。

The tag then should contain a URL like: 然后,标记应包含如下网址:

kuiperstimestamp://ts/20130506T034536.293

You then create an intent filter for your service that includes a data element: 然后,为您的服务创建一个包含data元素的意图过滤器:

<intent-filter>
    <action android:name="android.nfc.action.TAG_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="kuiperstimestamp" />
</intent-filter>

Since the intent filter is rather specific, you don't get the app selection dialog (unless another app or service has the same specific intent filter which is unlikely). 由于意图过滤器非常具体,因此您不会看到应用程序选择对话框(除非另一个应用程序或服务具有相同的特定意图过滤器,这不太可能发生)。

This approach is less Android specific than using an AAR. 与使用AAR相比,这种方法对Android的要求更低。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM