1

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()は使用できません。これの代わりに何を使用する必要がありますか、またはそれを行う方法は?

どんな助けでもありがたいです。すでにあなたの助けをありがとう

4

1 に答える 1

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

于 2012-06-11T12:47:16.007 に答える