Using Serial with Processing for Android

The following code will find the Bluetooth devices paired with my Samsung tablet:

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import java.util.Set;

String[] devices = {};
 
 void findPairedBluetoothDevices() {
 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
 if (adapter == null) {
    println("Device doesn't support Bluetooth.");
 } else {
   Set<BluetoothDevice> pairedDevices = adapter.getBondedDevices();
   if (pairedDevices.size() > 0) {
    // Get the name and address of each paired device.
     for (BluetoothDevice device : pairedDevices) {
       String deviceName = device.getName();
       String deviceHardwareAddress = device.getAddress(); // MAC address
       String deviceInfo = deviceName + "\n   " + deviceHardwareAddress;
       devices = append(devices, deviceInfo);
       println(deviceInfo);
     }       
  }
 }
}

void setup() {
  fullScreen();
  orientation(LANDSCAPE);
  findPairedBluetoothDevices();
}

void draw() {
  color BLUE = color(64,124,188);
  background(BLUE);
  fill(255);
  textSize(48);
  for(int j = 0; j < devices.length; j++) {
  text(devices[j], 130, 100 + (180 * j), 500, 180);
  }
}

3 Likes