安卓NFC启动服务 [英] Android NFC start service

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

问题描述

我很好奇Android NFC service 是否允许开发者在 时启动Service(或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 数据的标签但无法扫描时映射到 MIMEURI,标签调度系统尝试启动一个具有 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.

似乎只能启动一个新的 Activity,而不能启动 Service,尽管它可以接收相同的 Intent 过滤器.

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

推荐答案

虽然不是直接方法,但你可以有一个准系统Activity,它会立即启动一个服务,然后退出:

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();
}

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

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