我正在尝试制作一项等待 NFC 标签并执行某些操作的服务。我可以在 Activity 中使用以下代码块来做到这一点,但即使在研究之后也不知道如何在服务中实现它。
@Override
protected void onResume() {
super.onResume(); // Sticky notes received from Android if
enableNdefExchangeMode();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
do_something();
}
}
我想在服务中这样做。我不能使用 super.onResume()。我应该用什么代替这个,或者如何做?
任何帮助将不胜感激。已经感谢您的帮助
最佳答案
给你:)
我也建议在这里看看:http://developer.android.com/guide/topics/nfc/index.html更多文档、示例和代码
<service
android:name="com.myexample.ServiceName" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/com.example.android.beam" />
</intent-filter>
</service>
更新:这是一个完整的例子:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/nfc/ForegroundDispatch.html
关于android - Android服务的onresume方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10980315/