diff options
| author | Martijn Coenen <maco@google.com> | 2014-01-29 17:28:04 -0800 |
|---|---|---|
| committer | Martijn Coenen <maco@google.com> | 2014-02-14 10:58:30 -0800 |
| commit | 7fe9fa163ccd2ec34cbf533be4422aa66356431f (patch) | |
| tree | 28e875d5326ddf073f277677e29857d5965e8e01 /core/java/android/nfc/NfcAdapter.java | |
| parent | 44bb4e9cd51b6ea114465f74a725455500be130c (diff) | |
Add an API to manually invoke Android Beam.
Activities can call NfcAdapter.invokeBeam() to
manually invoke the Beam animation. Any NFC tap
is then enough to complete the transaction.
Also, added NdefRecord convenience method for
creating Text records.
Bug: 5134061
Change-Id: Ia9df360d1d7e8451157c85a6d12f2a4eec924960
Diffstat (limited to 'core/java/android/nfc/NfcAdapter.java')
| -rw-r--r-- | core/java/android/nfc/NfcAdapter.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java index e8b74377910d..6751a523312d 100644 --- a/core/java/android/nfc/NfcAdapter.java +++ b/core/java/android/nfc/NfcAdapter.java @@ -1249,6 +1249,45 @@ public final class NfcAdapter { } /** + * Manually invoke Android Beam to share data. + * + * <p>The Android Beam animation is normally only shown when two NFC-capable + * devices come into range. + * By calling this method, an Activity can invoke the Beam animation directly + * even if no other NFC device is in range yet. The Beam animation will then + * prompt the user to tap another NFC-capable device to complete the data + * transfer. + * + * <p>The main advantage of using this method is that it avoids the need for the + * user to tap the screen to complete the transfer, as this method already + * establishes the direction of the transfer and the consent of the user to + * share data. Callers are responsible for making sure that the user has + * consented to sharing data on NFC tap. + * + * <p>Note that to use this method, the passed in Activity must have already + * set data to share over Beam by using method calls such as + * {@link #setNdefPushMessageCallback(CreateNdefMessageCallback, Activity, Activity...)} or + * {@link #setBeamPushUrisCallback(CreateBeamUrisCallback, Activity)}. + * + * @param activity the current foreground Activity that has registered data to share + * @return whether the Beam animation was successfully invoked + */ + public boolean invokeBeam(Activity activity) { + if (activity == null) { + throw new NullPointerException("activity may not be null."); + } + enforceResumed(activity); + try { + sService.invokeBeam(); + return true; + } catch (RemoteException e) { + Log.e(TAG, "invokeBeam: NFC process has died."); + attemptDeadServiceRecovery(e); + return false; + } + } + + /** * Enable NDEF message push over NFC while this Activity is in the foreground. * * <p>You must explicitly call this method every time the activity is |
