Android NFC启动服务

发布于 2024-12-10 11:22:44 字数 416 浏览 6 评论 0原文

我很好奇 Android NFC 服务 是否允许开发者在 NFC 时启动 Service(或 IntentService)代码>标签被扫描?

来自 Android 开发者:

当设备扫描带有 NDEF 数据的标签,但无法扫描时 映射到 MIMEURI,标签调度系统尝试启动一个 具有 ACTION_TECH_DISCOVERED 意图的活动

看来只能启动新的 Activity,而不能启动 Service,尽管它可以接收相同的 Intent 过滤器。

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

From Android Developers:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各空 2024-12-17 11:22:44

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

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

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文