Android NFC framework introduction and develop guide(16)
发布时间:2021-06-07
发布时间:2021-06-07
Android system NFC framework introduction and develop guide
the Android system checks the first record of an NdefMessage to determine the MIME type or URI of the tag, which is used to create an intent for applications to filter. The following code shows you how to create an AAR:
Beaming NDEF Messages to Other Devices
Android Beam allows simple peer-to-peer data exchange between two Android-powered devices. The application that wants to beam data to another device must be in the foreground and the device receiving the data must not be locked. When the beaming device comes in close enough contact with a receiving device, the beaming device displays the "Touch to Beam" UI. The user can then choose whether or not to beam the message to the receiving device.
Note: Foreground NDEF pushing was available at API level 10, which provides similar
functionality to Android Beam. These APIs have since been deprecated, but are available to support older devices. See enableForegroundNdefPush() for more
information.
You can enable Android Beam for your application by calling one of the two methods:
setNdefPushMessage(): Accepts an NdefMessage to set as the message to beam. Automatically beams the message when two devices are in close enough proximity. setNdefPushMessageCallback(): Accepts a callback that contains a
createNdefMessage() which is called when a device is in range to beam data to. The callback lets you create the NDEF message only when necessary. An activity can only push one NDEF message at a time, so setNdefPushMessageCallback() takes precedence over setNdefPushMessage() if both are set. To use Android Beam, the following general guidelines must be met:
The activity that is beaming the data must be in the foreground. Both devices must have their screens unlocked. You must encapsulate the data that you are beaming in an NdefMessage object. The NFC device that is receiving the beamed data must support the com.android.npp
NDEF push protocol or NFC Forum's SNEP (Simple NDEF Exchange Protocol). The
com.android.npp protocol is required for devices on API level 9 (Android 2.3) to API
下一篇:上半年工作总结