适用于Android服务的Onresume方法

时间:2012-06-11 12:42:42

标签: android android-service

我正在尝试制作等待NFC标签并做某事的服务。我可以在活动中使用以下代码块来完成它,但即使在研究之后也不知道如何在服务中实现它。

@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()。我该怎么用而不是这个,或者怎么做?

任何帮助将不胜感激。非常感谢您的帮助

1 个答案:

答案 0 :(得分:1)

你在这里:)

我还建议您在这里查看: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

相关问题