use of android.bluetooth.BluetoothDevice in project Android-Developers-Samples by johnjohndoe.
the class DeviceScanActivity method onListItemClick.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
if (device == null)
return;
final Intent intent = new Intent(this, DeviceControlActivity.class);
intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_NAME, device.getName());
intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
if (mScanning) {
mBluetoothAdapter.stopLeScan(mLeScanCallback);
mScanning = false;
}
startActivity(intent);
}
use of android.bluetooth.BluetoothDevice in project platform_frameworks_base by android.
the class MidiService method addDeviceLocked.
// synchronize on mDevicesByInfo
private MidiDeviceInfo addDeviceLocked(int type, int numInputPorts, int numOutputPorts, String[] inputPortNames, String[] outputPortNames, Bundle properties, IMidiDeviceServer server, ServiceInfo serviceInfo, boolean isPrivate, int uid) {
int id = mNextDeviceId++;
MidiDeviceInfo deviceInfo = new MidiDeviceInfo(type, id, numInputPorts, numOutputPorts, inputPortNames, outputPortNames, properties, isPrivate);
if (server != null) {
try {
server.setDeviceInfo(deviceInfo);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in setDeviceInfo()");
return null;
}
}
Device device = null;
BluetoothDevice bluetoothDevice = null;
if (type == MidiDeviceInfo.TYPE_BLUETOOTH) {
bluetoothDevice = (BluetoothDevice) properties.getParcelable(MidiDeviceInfo.PROPERTY_BLUETOOTH_DEVICE);
device = mBluetoothDevices.get(bluetoothDevice);
if (device != null) {
device.setDeviceInfo(deviceInfo);
}
}
if (device == null) {
device = new Device(server, deviceInfo, serviceInfo, uid);
}
mDevicesByInfo.put(deviceInfo, device);
if (bluetoothDevice != null) {
mBluetoothDevices.put(bluetoothDevice, device);
}
synchronized (mClients) {
for (Client c : mClients.values()) {
c.deviceAdded(device);
}
}
return deviceInfo;
}
use of android.bluetooth.BluetoothDevice in project platform_frameworks_base by android.
the class MidiService method openBluetoothDevice.
@Override
public void openBluetoothDevice(IBinder token, BluetoothDevice bluetoothDevice, IMidiDeviceOpenCallback callback) {
Client client = getClient(token);
if (client == null)
return;
// Bluetooth devices are created on demand
Device device;
synchronized (mDevicesByInfo) {
device = mBluetoothDevices.get(bluetoothDevice);
if (device == null) {
device = new Device(bluetoothDevice);
mBluetoothDevices.put(bluetoothDevice, device);
}
}
// clear calling identity so bindService does not fail
long identity = Binder.clearCallingIdentity();
try {
client.addDeviceConnection(device, callback);
} finally {
Binder.restoreCallingIdentity(identity);
}
}
use of android.bluetooth.BluetoothDevice in project BtSerial by arduino.
the class BtSerial method list.
/**
* Returns a list of bonded (paired) devices.
*
* @param info
* flag to control display of additional information (device
* names and types)
* @return String array
*/
public String[] list(boolean info) {
Vector<String> list = new Vector<String>();
Set<BluetoothDevice> devices;
try {
devices = mAdapter.getBondedDevices();
// convert the devices 'set' into an array so that we can
// perform string functions on it
Object[] deviceArray = devices.toArray();
// remoteDevice and then print it's name
for (int i = 0; i < devices.size(); i++) {
BluetoothDevice thisDevice = mAdapter.getRemoteDevice(deviceArray[i].toString());
String element = thisDevice.getAddress();
if (info) {
element += "," + thisDevice.getName() + "," + thisDevice.getBluetoothClass().getMajorDeviceClass();
// information
}
list.addElement(element);
}
} catch (UnsatisfiedLinkError e) {
Log.e(TAG, Log.getStackTraceString(e));
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
}
String[] outgoing = new String[list.size()];
list.copyInto(outgoing);
return outgoing;
}
use of android.bluetooth.BluetoothDevice in project coursera-android by aporter.
the class DataTransferActivity method selectServer.
private void selectServer() {
setButtonsEnabled(false);
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
ArrayList<String> pairedDeviceStrings = new ArrayList<String>();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
pairedDeviceStrings.add(device.getName() + "\n" + device.getAddress());
}
}
Intent showDevicesIntent = new Intent(this, ShowDevices.class);
showDevicesIntent.putStringArrayListExtra("devices", pairedDeviceStrings);
startActivityForResult(showDevicesIntent, SELECT_SERVER);
}
Aggregations