Search in sources :

Example 16 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.

the class BluetoothService method dumpInputDeviceProfile.

private void dumpInputDeviceProfile(PrintWriter pw) {
    pw.println("\n--Bluetooth Service- Input Device Profile");
    if (mInputDevice != null) {
        List<BluetoothDevice> deviceList = mInputDevice.getConnectedDevices();
        if (deviceList.size() == 0) {
            pw.println("No input devices connected");
        } else {
            pw.println("Number of connected devices:" + deviceList.size());
            BluetoothDevice device = deviceList.get(0);
            pw.println("getConnectedDevices[0] = " + device);
            pw.println("Priority of Connected device = " + mInputDevice.getPriority(device));
            switch(mInputDevice.getConnectionState(device)) {
                case BluetoothInputDevice.STATE_CONNECTING:
                    pw.println("getConnectionState() = STATE_CONNECTING");
                    break;
                case BluetoothInputDevice.STATE_CONNECTED:
                    pw.println("getConnectionState() = STATE_CONNECTED");
                    break;
                case BluetoothInputDevice.STATE_DISCONNECTING:
                    pw.println("getConnectionState() = STATE_DISCONNECTING");
                    break;
            }
        }
        deviceList.clear();
        deviceList = mInputDevice.getDevicesMatchingConnectionStates(new int[] { BluetoothProfile.STATE_CONNECTED, BluetoothProfile.STATE_DISCONNECTED });
        pw.println("--Connected and Disconnected input devices");
        for (BluetoothDevice device : deviceList) {
            pw.println(device);
        }
    }
    mAdapter.closeProfileProxy(BluetoothProfile.INPUT_DEVICE, mBluetoothHeadset);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 17 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.

the class BluetoothEventLoop method onNetworkDeviceDisconnected.

/**
     * Called by native code on a DeviceDisconnected signal from
     * org.bluez.NetworkServer.
     *
     * @param address the MAC address of the disconnected device
     */
private void onNetworkDeviceDisconnected(String address) {
    BluetoothDevice device = mAdapter.getRemoteDevice(address);
    mBluetoothService.handlePanDeviceStateChange(device, BluetoothPan.STATE_DISCONNECTED, BluetoothPan.LOCAL_NAP_ROLE);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 18 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.

the class BluetoothA2dpService method onBluetoothDisable.

private synchronized void onBluetoothDisable() {
    if (!mAudioDevices.isEmpty()) {
        BluetoothDevice[] devices = new BluetoothDevice[mAudioDevices.size()];
        devices = mAudioDevices.keySet().toArray(devices);
        for (BluetoothDevice device : devices) {
            int state = getConnectionState(device);
            switch(state) {
                case BluetoothA2dp.STATE_CONNECTING:
                case BluetoothA2dp.STATE_CONNECTED:
                case BluetoothA2dp.STATE_PLAYING:
                    disconnectSinkNative(mBluetoothService.getObjectPathFromAddress(device.getAddress()));
                    handleSinkStateChange(device, state, BluetoothA2dp.STATE_DISCONNECTED);
                    break;
                case BluetoothA2dp.STATE_DISCONNECTING:
                    handleSinkStateChange(device, BluetoothA2dp.STATE_DISCONNECTING, BluetoothA2dp.STATE_DISCONNECTED);
                    break;
            }
        }
        mAudioDevices.clear();
    }
    mAudioManager.setParameters(BLUETOOTH_ENABLED + "=false");
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 19 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.

the class BluetoothA2dpService method onConnectSinkResult.

/**
     * Called by native code for the async response to a Connect
     * method call to org.bluez.AudioSink.
     *
     * @param deviceObjectPath the object path for the connecting device
     * @param result true on success; false on error
     */
private void onConnectSinkResult(String deviceObjectPath, boolean result) {
    // when we a Sink Property Change
    if (!result) {
        if (deviceObjectPath != null) {
            String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath);
            if (address == null)
                return;
            BluetoothDevice device = mAdapter.getRemoteDevice(address);
            int state = getConnectionState(device);
            handleSinkStateChange(device, state, BluetoothA2dp.STATE_DISCONNECTED);
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 20 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project XobotOS by xamarin.

the class BluetoothA2dpService method onBluetoothEnable.

private synchronized void onBluetoothEnable() {
    String devices = mBluetoothService.getProperty("Devices", true);
    if (devices != null) {
        String[] paths = devices.split(",");
        for (String path : paths) {
            String address = mBluetoothService.getAddressFromObjectPath(path);
            BluetoothDevice device = mAdapter.getRemoteDevice(address);
            ParcelUuid[] remoteUuids = mBluetoothService.getRemoteUuids(address);
            if (remoteUuids != null)
                if (BluetoothUuid.containsAnyUuid(remoteUuids, new ParcelUuid[] { BluetoothUuid.AudioSink, BluetoothUuid.AdvAudioDist })) {
                    addAudioSink(device);
                }
        }
    }
    mAudioManager.setParameters(BLUETOOTH_ENABLED + "=true");
    mAudioManager.setParameters("A2dpSuspended=false");
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothDevice(android.bluetooth.BluetoothDevice)

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