Android 5.0 APIs
NFC enhancements
Android 5.0 adds these enhancements to enable wider and more flexible use of NFC:
Android Beam is now available in the share menu.
Your app can invoke the Android Beam on the user’s device to share data by calling invokeBeam()
. This avoids the need for the user to manually tap the device against another NFC-capable device to complete the data transfer.
You can use the new [createTextRecord()](https://developer.android.com/reference/android/nfc/NdefRecord.html#createTextRecord(java.lang.String, java.lang.String))
method to create an NDEF record containing UTF-8 text data.
If you are developing a payment app, you now have the ability to register an NFC application ID (AID) dynamically by calling [registerAidsForService()](https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation.html#registerAidsForService(android.content.ComponentName, java.lang.String, java.util.List<java.lang.String>))
. You can also use [setPreferredService()](https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation.html#setPreferredService(android.app.Activity, android.content.ComponentName))
to set the preferred card emulation service that should be used when a specific activity is in the foreground.
Android 4.4 APIs
NFC reader mode
A new NFC reader mode allows an activity to restrict all NFC activity to only reading the types of tags the activity is interested in while in the foreground. You can enable reader mode for your activity with [enableReaderMode()](https://developer.android.com/reference/android/nfc/NfcAdapter.html#enableReaderMode(android.app.Activity, android.nfc.NfcAdapter.ReaderCallback, int, android.os.Bundle))
, providing an implementation of NfcAdapter.ReaderCallback
that receives a callback when new tags are detected.
This new capability, in conjunction with host card emulation, allows Android to operate on both ends of a mobile payment interface: One devices operates as the payment terminal (a device running a reader mode activity) and another device operates as the payment client (a device emulating an NFC card).
Android 4.1 APIs
Android Beam
Android Beam™ now supports large payload transfers over Bluetooth. When you define the data to transfer with either the new [setBeamPushUris()](https://developer.android.com/reference/android/nfc/NfcAdapter.html#setBeamPushUris(android.net.Uri[], android.app.Activity))
method or the new callback interface NfcAdapter.CreateBeamUrisCallback
, Android hands off the data transfer to Bluetooth or another alternate transport to achieve faster transfer speeds. This is especially useful for large payloads such as image and audio files and requires no visible pairing between the devices. No additional work is required by your app to take advantage of transfers over Bluetooth.
The [setBeamPushUris()](https://developer.android.com/reference/android/nfc/NfcAdapter.html#setBeamPushUris(android.net.Uri[], android.app.Activity))
method takes an array of Uri
objects that specify the data you want to transfer from your app. Alternatively, you can implement the NfcAdapter.CreateBeamUrisCallback
interface, which you can specify for your activity by calling [setBeamPushUrisCallback()](https://developer.android.com/reference/android/nfc/NfcAdapter.html#setBeamPushUrisCallback(android.nfc.NfcAdapter.CreateBeamUrisCallback, android.app.Activity))
.
When using the callback interface, the system calls the interface's createBeamUris()
method when the user executes a share with Android Beam so that you can define the URIs to share at share-time. This is useful if the URIs to share might vary depending on the user context within the activity, whereas calling [setBeamPushUris()](https://developer.android.com/reference/android/nfc/NfcAdapter.html#setBeamPushUris(android.net.Uri[], android.app.Activity))
is useful when the URIs to share are unchanging and you can safely define them ahead of time.
网友评论