Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1031)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/nfc/BeamController.java

Issue 615213003: Upstream NFC beam URL sharing code and add it to ChromeShell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated sync shell manifest Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.");
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698