安卓NFC启动服务 [英] Android NFC start service
问题描述
我很好奇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
数据的标签但无法扫描时映射到 MIME
或 URI
,标签调度系统尝试启动一个具有 ACTION_TECH_DISCOVERED
意图的 活动.
When a device scans a tag that has
NDEF
data on it, but could not be mapped to aMIME
orURI
, the tag dispatch system tries to start an activity with theACTION_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屋!