| Index: chrome/android/java/src/org/chromium/chrome/browser/nfc/BeamController.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/nfc/BeamController.java b/chrome/android/java/src/org/chromium/chrome/browser/nfc/BeamController.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..105daa63a9b7e3a2e53e9b61bd271b6da7059251
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/nfc/BeamController.java
|
| @@ -0,0 +1,34 @@
|
| +// Copyright 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.chrome.browser.nfc;
|
| +
|
| +import android.app.Activity;
|
| +import android.nfc.NfcAdapter;
|
| +import android.util.Log;
|
| +
|
| +/**
|
| + * Initializes Android Beam (sharing URL via NFC) for devices that have NFC. If user taps their
|
| + * device with another Beam capable device, then Chrome gets the current URL, filters for security
|
| + * and returns the result to Android.
|
| + */
|
| +public final class BeamController {
|
| + /**
|
| + * If the device has NFC, construct a BeamCallback and pass it to Android.
|
| + *
|
| + * @param activity Activity that is sending out beam messages.
|
| + * @param provider Provider that returns the URL that should be shared.
|
| + */
|
| + public static void registerForBeam(final Activity activity, final BeamProvider provider) {
|
| + final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
|
| + if (nfcAdapter == null) return;
|
| + try {
|
| + final BeamCallback beamCallback = new BeamCallback(activity, provider);
|
| + nfcAdapter.setNdefPushMessageCallback(beamCallback, activity);
|
| + nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity);
|
| + } catch (IllegalStateException e) {
|
| + Log.w("BeamController", "NFC registration failure. Can't retry, giving up.");
|
| + }
|
| + }
|
| +}
|
|
|