Android NFC start service

独自空忆成欢 提交于 2019-12-18 04:46:12

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/7819098/android-nfc-start-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!