Search in sources :

Example 6 with BluetoothDevice

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);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) Intent(android.content.Intent)

Example 7 with BluetoothDevice

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;
}
Also used : MidiDeviceInfo(android.media.midi.MidiDeviceInfo) BluetoothDevice(android.bluetooth.BluetoothDevice) BluetoothDevice(android.bluetooth.BluetoothDevice) RemoteException(android.os.RemoteException)

Example 8 with BluetoothDevice

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);
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 9 with BluetoothDevice

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;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) Vector(java.util.Vector) IOException(java.io.IOException)

Example 10 with BluetoothDevice

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);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Aggregations

BluetoothDevice (android.bluetooth.BluetoothDevice)100 Intent (android.content.Intent)13 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)11 ParcelUuid (android.os.ParcelUuid)9 RemoteException (android.os.RemoteException)9 ScanFilter (android.bluetooth.le.ScanFilter)5 Parcel (android.os.Parcel)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 IOException (java.io.IOException)5 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)5 IntentFilter (android.content.IntentFilter)4 MidiDeviceInfo (android.media.midi.MidiDeviceInfo)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)2