Android的NFC启动服务 [英] Android NFC start service

查看:917
本文介绍了Android的NFC启动服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,如果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();
}

这篇关于Android的NFC启动服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆