Stay organized with collections
Save and categorize content based on your preferences.
CreateNdefMessageCallback
interface CreateNdefMessageCallback
A callback to be invoked when another NFC device capable of NDEF push (Android Beam) is within range.
Implement this interface and pass it to NfcAdapter#setNdefPushMessageCallback setNdefPushMessageCallback()
in order to create an NdefMessage
at the moment that another device is within range for NFC. Using this callback allows you to create a message with data that might vary based on the content currently visible to the user. Alternatively, you can call setNdefPushMessage setNdefPushMessage()
if the NdefMessage
always contains the same data.
Summary
Public methods
createNdefMessage
abstract fun createNdefMessage(event: NfcEvent!): NdefMessage!
Deprecated: Deprecated in Java.
Called to provide a NdefMessage
to push.
This callback is usually made on a binder thread (not the UI thread).
Called when this device is in range of another device that might support NDEF push. It allows the application to create the NDEF message only when it is required.
NDEF push cannot occur until this method returns, so do not block for too long.
The Android operating system will usually show a system UI on top of your activity during this time, so do not try to request input from the user to complete the callback, or provide custom NDEF push UI. The user probably will not see it.
Return |
NdefMessage! |
NDEF message to push, or null to not provide a message |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# NfcAdapter.CreateNdefMessageCallback\n\nAdded in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \nDeprecated in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nCreateNdefMessageCallback\n=========================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/nfc/NfcAdapter.CreateNdefMessageCallback \"View this page in Java\") \n\n```\ninterface CreateNdefMessageCallback\n```\n\n|-------------------------------------------------------|\n| [android.nfc.NfcAdapter.CreateNdefMessageCallback](#) |\n\n*** ** * ** ***\n\n| **This interface was deprecated in API level 29.**\n|\n| this feature is removed. File sharing can work using other technology like Bluetooth.\n\nA callback to be invoked when another NFC device capable of NDEF push (Android Beam) is within range.\n\nImplement this interface and pass it to `NfcAdapter#setNdefPushMessageCallback setNdefPushMessageCallback()` in order to create an [NdefMessage](/reference/kotlin/android/nfc/NdefMessage) at the moment that another device is within range for NFC. Using this callback allows you to create a message with data that might vary based on the content currently visible to the user. Alternatively, you can call `setNdefPushMessage setNdefPushMessage()` if the [NdefMessage](/reference/kotlin/android/nfc/NdefMessage) always contains the same data.\n\nSummary\n-------\n\n| Public methods ||\n|--------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [NdefMessage](/reference/kotlin/android/nfc/NdefMessage)! | [createNdefMessage](#createNdefMessage(android.nfc.NfcEvent))`(`event:` `[NfcEvent](/reference/kotlin/android/nfc/NfcEvent)!`)` Called to provide a [NdefMessage](/reference/kotlin/android/nfc/NdefMessage) to push. |\n\nPublic methods\n--------------\n\n### createNdefMessage\n\nAdded in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun createNdefMessage(event: NfcEvent!): NdefMessage!\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nCalled to provide a [NdefMessage](/reference/kotlin/android/nfc/NdefMessage) to push.\n\nThis callback is usually made on a binder thread (not the UI thread).\n\nCalled when this device is in range of another device that might support NDEF push. It allows the application to create the NDEF message only when it is required.\n\nNDEF push cannot occur until this method returns, so do not block for too long.\n\nThe Android operating system will usually show a system UI on top of your activity during this time, so do not try to request input from the user to complete the callback, or provide custom NDEF push UI. The user probably will not see it.\n\n| Parameters ||\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `event` | [NfcEvent](/reference/kotlin/android/nfc/NfcEvent)!: [NfcEvent](/reference/kotlin/android/nfc/NfcEvent) with the [NfcEvent.nfcAdapter](/reference/kotlin/android/nfc/NfcEvent#nfcAdapter:android.nfc.NfcAdapter) field set |\n\n| Return ||\n|-----------------------------------------------------------|--------------------------------------------------------|\n| [NdefMessage](/reference/kotlin/android/nfc/NdefMessage)! | NDEF message to push, or null to not provide a message |"]]