OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.nfc; |
| 6 |
| 7 import android.app.Activity; |
| 8 import android.nfc.NfcAdapter; |
| 9 import android.util.Log; |
| 10 |
| 11 /** |
| 12 * Initializes Android Beam (sharing URL via NFC) for devices that have NFC. If
user taps their |
| 13 * device with another Beam capable device, then Chrome gets the current URL, fi
lters for security |
| 14 * and returns the result to Android. |
| 15 */ |
| 16 public final class BeamController { |
| 17 /** |
| 18 * If the device has NFC, construct a BeamCallback and pass it to Android. |
| 19 * |
| 20 * @param activity Activity that is sending out beam messages. |
| 21 * @param provider Provider that returns the URL that should be shared. |
| 22 */ |
| 23 public static void registerForBeam(final Activity activity, final BeamProvid
er provider) { |
| 24 final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity); |
| 25 if (nfcAdapter == null) return; |
| 26 try { |
| 27 final BeamCallback beamCallback = new BeamCallback(activity, provide
r); |
| 28 nfcAdapter.setNdefPushMessageCallback(beamCallback, activity); |
| 29 nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity); |
| 30 } catch (IllegalStateException e) { |
| 31 Log.w("BeamController", "NFC registration failure. Can't retry, givi
ng up."); |
| 32 } |
| 33 } |
| 34 } |
OLD | NEW |