Android的NFC启动服务 [英] Android NFC start service
问题描述
我很好奇,如果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 aMIME
orURI
, the tag dispatch system tries to start an activity with theACTION_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屋!