问题
I am trying to make a service which waits NFC tags and does something. I can do it with following code block in an activity but have no idea, even after researches, how to implement it in a service.
@Override
protected void onResume() {
super.onResume(); // Sticky notes received from Android if
enableNdefExchangeMode();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
do_something();
}
}
I want to do this in a service. i can not use super.onResume(). What should I use instead of this, or how to do it?
Any helps will be appreciated. Thanks already for your helps
回答1:
Here you are :)
I also suggest to take a look here: http://developer.android.com/guide/topics/nfc/index.html for more documentations, examples and code
<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>
UPDATE: this is a complete example: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/nfc/ForegroundDispatch.html
来源:https://stackoverflow.com/questions/10980315/onresume-method-for-android-services