Here is the test code that I am using :
public class IOConnectDirect extends Activity {
private static final String TAG = \"IOConnectDirect\";
private static f
Try this code:
private final BroadcastReceiver mBluetoothPickerReceiver = new BluetoothConnectActivityReceiver(this);
void connectToService(String defaultAdapter) {
if (defaultAdapter == null) {
registerReceiver(mBluetoothPickerReceiver, new IntentFilter(BluetoothDevicePicker.ACTION_DEVICE_SELECTED));
startActivity(new Intent(BluetoothDevicePicker.ACTION_LAUNCH)
.putExtra(BluetoothDevicePicker.EXTRA_NEED_AUTH, false)
.putExtra(BluetoothDevicePicker.EXTRA_FILTER_TYPE, BluetoothDevicePicker.FILTER_TYPE_ALL)
.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS));
} else {
mCardroid.getCardroidService().connectTo(defaultAdapter);
}
}
public class BluetoothConnectActivityReceiver extends BroadcastReceiver {
private BluetoothConnectActivity bluetoothConnectActivity;
public BluetoothConnectActivityReceiver(BluetoothConnectActivity bluetoothConnectActivity) {
this.bluetoothConnectActivity = bluetoothConnectActivity;
}
@Override
public void onReceive(Context context, Intent intent) {
if(BluetoothDevicePicker.ACTION_DEVICE_SELECTED.equals(intent.getAction())) {
context.unregisterReceiver(this);
BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
bluetoothConnectActivity.connectToService(device.getAddress());
}
}
}
The reference of complete code is :
http://code.google.com/p/carbot/source/browse/trunk/src/net/cardroid/?r=8