1

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

JonasVautherin
  • 7,297
  • 6
  • 49
  • 95
akbas
  • 175
  • 4
  • 14

1 Answers1

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

StErMi
  • 5,389
  • 5
  • 48
  • 71
  • Thanks for your answer but I couldnt understand it. I want that my service, which will be created when my activity starts, waits a NDEF_DISCOVERED tag and does something. I implemented that in activity, need only service.. – akbas Jun 11 '12 at 13:17
  • Do you need to know how to bind to a service? – Hauke Ingmar Schmidt Jun 11 '12 at 14:33
  • no, but i will use this example after getting message from other device. http://stackoverflow.com/questions/8802157/how-to-use-localbroadcastmanager – akbas Jun 11 '12 at 14:48