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();
}
}
});
}
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);
}
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);
}
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);
}
}
}
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);
}
Aggregations