Android的NFC启动服务Android、NFC

由网友(别堕落、你没资格)分享简介:我很好奇,如果Android的 NFC服务允许开发人员开始服务(或 IntentService 对于这个问题),当 NFC 标签进行扫描?I'm curious if Android NFC service allows the developer to start a Service (or IntentServi...

我很好奇,如果Android的 NFC服务允许开发人员开始服务(或 IntentService 对于这个问题),当 NFC 标签进行扫描?

I'm curious if Android NFC service allows the developer to start a Service (or IntentService for that matter) when NFC tag is scanned?

这是Android开发者:

From Android Developers:

当一个设备会扫描上有 NDEF 数据的标签,但不能   映射到 MIME URI ,标签调度系统尝试启动   活动与 ACTION_TECH_DISCOVERED 意图。

When a device scans a tag that has NDEF data on it, but could not be mapped to a MIME or URI, the tag dispatch system tries to start an activity with the ACTION_TECH_DISCOVERED intent.

看来,只是一个新的活动可以启动,而不是服务,虽然也可以收到同样的意图过滤器。

It appears that only a new Activity can be launched, not Service, although it could receive the same Intent filter.

推荐答案

虽然不是直接的方法,你可以有一个准系统活动,将立即启动一项服务,然后退出:

Although not the direct method, you could have a barebones Activity that will immediately start a service, then quit:

@Override
public void onCreate(Bundle savedInstanceState) {
  Context con = getApplicationContext();
  Intent srv = new Intent(con, TargetService.class);
  con.startService(srv);
  finish();
}
阅读全文

相关推荐

最新文章