Onresume method for Android services

左心房为你撑大大i 提交于 2019-12-11 07:20:00

问题


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

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