aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/PairingBroadcastReceiver.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/PairingBroadcastReceiver.java')
-rw-r--r--src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/PairingBroadcastReceiver.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/PairingBroadcastReceiver.java b/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/PairingBroadcastReceiver.java
new file mode 100644
index 0000000..0cfd362
--- /dev/null
+++ b/src/main/java/com/google/android/mobly/snippet/bundled/bluetooth/PairingBroadcastReceiver.java
@@ -0,0 +1,30 @@
+package com.google.android.mobly.snippet.bundled.bluetooth;
+
+import android.annotation.TargetApi;
+import android.bluetooth.BluetoothDevice;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Build;
+import com.google.android.mobly.snippet.util.Log;
+
+@TargetApi(Build.VERSION_CODES.KITKAT)
+public class PairingBroadcastReceiver extends BroadcastReceiver {
+ private final Context mContext;
+ public static IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
+
+ public PairingBroadcastReceiver(Context context) {
+ mContext = context;
+ }
+
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
+ BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ Log.d("Confirming pairing with device: " + device.getAddress());
+ device.setPairingConfirmation(true);
+ mContext.unregisterReceiver(this);
+ }
+ }
+}