Search in sources :

Example 11 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project coursera-android by aporter.

the class ShowDevices method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    final ListView lv = getListView();
    final TextView footer = new TextView(this);
    footer.setText("Discover More Devices");
    lv.setFooterDividersEnabled(true);
    lv.addFooterView(footer, null, true);
    final List<String> devices = getIntent().getStringArrayListExtra("devices");
    mArrayAdapter = new ArrayAdapter<String>(this, R.layout.list_item, devices);
    setListAdapter(mArrayAdapter);
    getListView().setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
            if (parent.getAdapter().getItemViewType(pos) == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
                mBluetoothAdapter.startDiscovery();
            } else {
                String tmp = (String) parent.getItemAtPosition(pos);
                BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(tmp.split("\n")[1]);
                Intent data = new Intent();
                data.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
                setResult(RESULT_OK, data);
                finish();
            }
        }
    });
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) BluetoothDevice(android.bluetooth.BluetoothDevice) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) TextView(android.widget.TextView)

Example 12 with BluetoothDevice

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

the class BluetoothHealthProfileHandler method onHealthDeviceChannelChanged.

/*package*/
void onHealthDeviceChannelChanged(String devicePath, String channelPath, boolean exists) {
    debugLog("onHealthDeviceChannelChanged: devicePath: " + devicePath + "ChannelPath: " + channelPath + "Exists: " + exists);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    String address = mBluetoothService.getAddressFromObjectPath(devicePath);
    if (address == null)
        return;
    BluetoothDevice device = adapter.getRemoteDevice(address);
    BluetoothHealthAppConfiguration config;
    int state, prevState = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
    ParcelFileDescriptor fd;
    HealthChannel channel;
    config = findHealthApplication(device, channelPath);
    if (exists) {
        channel = findConnectingChannel(device, config);
        if (channel == null) {
            channel = new HealthChannel(device, config, null, false, channelPath);
            channel.mState = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
            mHealthChannels.add(channel);
        }
        channel.mChannelPath = channelPath;
        fd = mBluetoothService.getChannelFdNative(channelPath);
        if (fd == null) {
            errorLog("Error obtaining fd for channel:" + channelPath);
            disconnectChannel(device, config, channel.mId);
            return;
        }
        boolean mainChannel = getMainChannel(device, config) == null ? false : true;
        if (!mainChannel) {
            String mainChannelPath = mBluetoothService.getMainChannelNative(devicePath);
            if (mainChannelPath == null) {
                errorLog("Main Channel Path is null for devicePath:" + devicePath);
                return;
            }
            if (mainChannelPath.equals(channelPath))
                mainChannel = true;
        }
        channel.mChannelFd = fd;
        channel.mMainChannel = mainChannel;
        prevState = channel.mState;
        state = BluetoothHealth.STATE_CHANNEL_CONNECTED;
    } else {
        channel = findChannelByPath(device, channelPath);
        if (channel == null) {
            errorLog("Channel not found:" + config + ":" + channelPath);
            return;
        }
        mHealthChannels.remove(channel);
        channel.mChannelFd = null;
        prevState = channel.mState;
        state = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
    }
    channel.mState = state;
    callHealthChannelCallback(config, device, prevState, state, channel.mChannelFd, channel.mId);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ParcelFileDescriptor(android.os.ParcelFileDescriptor) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothHealthAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration)

Example 13 with BluetoothDevice

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

the class BluetoothInputProfileHandler method handleInputDevicePropertyChange.

void handleInputDevicePropertyChange(String address, boolean connected) {
    int state = connected ? BluetoothInputDevice.STATE_CONNECTED : BluetoothInputDevice.STATE_DISCONNECTED;
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothDevice device = adapter.getRemoteDevice(address);
    handleInputDeviceStateChange(device, state);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 14 with BluetoothDevice

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

the class BluetoothService method dumpPanProfile.

private void dumpPanProfile(PrintWriter pw) {
    pw.println("\n--Bluetooth Service- Pan Profile");
    if (mPan != null) {
        List<BluetoothDevice> deviceList = mPan.getConnectedDevices();
        if (deviceList.size() == 0) {
            pw.println("No Pan devices connected");
        } else {
            pw.println("Number of connected devices:" + deviceList.size());
            BluetoothDevice device = deviceList.get(0);
            pw.println("getConnectedDevices[0] = " + device);
            switch(mPan.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 = mPan.getDevicesMatchingConnectionStates(new int[] { BluetoothProfile.STATE_CONNECTED, BluetoothProfile.STATE_DISCONNECTED });
        pw.println("--Connected and Disconnected Pan devices");
        for (BluetoothDevice device : deviceList) {
            pw.println(device);
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 15 with BluetoothDevice

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

the class BluetoothService method dumpHeadsetService.

private void dumpHeadsetService(PrintWriter pw) {
    pw.println("\n--Headset Service--");
    if (mBluetoothHeadset != null) {
        List<BluetoothDevice> deviceList = mBluetoothHeadset.getConnectedDevices();
        if (deviceList.size() == 0) {
            pw.println("No headsets connected");
        } else {
            BluetoothDevice device = deviceList.get(0);
            pw.println("\ngetConnectedDevices[0] = " + device);
            dumpHeadsetConnectionState(pw, device);
            pw.println("getBatteryUsageHint() = " + mBluetoothHeadset.getBatteryUsageHint(device));
        }
        deviceList.clear();
        deviceList = mBluetoothHeadset.getDevicesMatchingConnectionStates(new int[] { BluetoothProfile.STATE_CONNECTED, BluetoothProfile.STATE_DISCONNECTED });
        pw.println("--Connected and Disconnected Headsets");
        for (BluetoothDevice device : deviceList) {
            pw.println(device);
            if (mBluetoothHeadset.isAudioConnected(device)) {
                pw.println("SCO audio connected to device:" + device);
            }
        }
    }
    mAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
}
Also used : 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