我正在用Android编写一个NFC应用程序,我在编写标签时遇到了一些小问题。我已经能够编写一个标签,但为了做到这一点,我在清单中使用了意图过滤器来检测它。但是,我想要做的是使用前台调度程序直接处理应用程序中的标记。我能够用前台调度器“捕捉”NDEF_DISCOVERED标签,但我不知道如何以同样的方式使用TECH_DISCOVERED。
下面的代码适用于NDEF_DISCOVERED:
// Setup an intent filter for all MIME based dispatches
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
try {
ndef.addDataType("*/*");
} catch (MalformedMimeTypeException e) {
throw new RuntimeException("fail", e);
}
mFilters = new IntentFilter[] {
ndef,
};
// Setup a tech list for all NfcF tags
mTechLists = new String[][] { new String[] { NfcF.class.getName() } };但是我应该为TECH_DISCOVERED做些什么呢?我试着这样做,但它不起作用:
IntentFilter ntech = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
mFilters = new IntentFilter[] {
ntech,
};
// Setup a tech list for all NfcF tags
mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}发布于 2011-04-14 17:59:47
我希望你能自己想出来。但是,对于那些没有这样做的人:您应该在mTechLists中指定适当的标记技术,您希望对其进行处理。不需要更改意图过滤器来指定ACTION_TECH_DISCOVERED,它应该可以很好地与ACTION_NDEF_DISCOVERED一起工作。干杯!!
https://stackoverflow.com/questions/5636134
复制相似问题