Java Code Examples for android.bluetooth.BluetoothClass#getDeviceClass()
The following examples show how to use
android.bluetooth.BluetoothClass#getDeviceClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BluetoothDeviceInfo.java From libcommon with Apache License 2.0 | 5 votes |
BluetoothDeviceInfo(final BluetoothDevice device) { name = device.getName(); address = device.getAddress(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { type = device.getType(); } else { type = 0; } final BluetoothClass clazz = device.getBluetoothClass(); deviceClass = clazz != null ? clazz.getDeviceClass() : 0; bondState = device.getBondState(); }
Example 2
Source File: NovarumbluetoothModule.java From NovarumBluetooth with MIT License | 5 votes |
@Override public void onReceive(Context context, Intent intent) { Message msg = Message.obtain(); String action = intent.getAction(); if(BluetoothDevice.ACTION_FOUND.equals(action)) { bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothClass blclass = intent.getParcelableExtra(BluetoothDevice.EXTRA_CLASS); int Majorclass = blclass.getMajorDeviceClass(); int minorclass = blclass.getDeviceClass(); devicelist = new KrollDict(); try { devicelist.put("name",bluetoothDevice.getName()); devicelist.put("macaddress",bluetoothDevice.getAddress()); devicelist.put("pairedstatus",bluetoothDevice.getBondState()); } catch (Exception e) { Log.w(TAG, "devicesFound exception: "+e.getMessage()); postError(e.getMessage()); } devicesFound(); } }
Example 3
Source File: BluetoothUtils8.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
public boolean canBluetooth() { // Detect if any bluetooth a device is available for call if (bluetoothAdapter == null) { // Device does not support Bluetooth return false; } boolean hasConnectedDevice = false; //If bluetooth is on if(bluetoothAdapter.isEnabled()) { //We get all bounded bluetooth devices // bounded is not enough, should search for connected devices.... Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); for(BluetoothDevice device : pairedDevices) { BluetoothClass bluetoothClass = device.getBluetoothClass(); if (bluetoothClass != null) { int deviceClass = bluetoothClass.getDeviceClass(); if(bluetoothClass.hasService(Service.RENDER) || deviceClass == Device.AUDIO_VIDEO_WEARABLE_HEADSET || deviceClass == Device.AUDIO_VIDEO_CAR_AUDIO || deviceClass == Device.AUDIO_VIDEO_HANDSFREE ) { //And if any can be used as a audio handset hasConnectedDevice = true; break; } } } } boolean retVal = hasConnectedDevice && audioManager.isBluetoothScoAvailableOffCall(); Log.d(THIS_FILE, "Can I do BT ? "+retVal); return retVal; }
Example 4
Source File: BluetoothController.java From dialogflow-android-client with Apache License 2.0 | 4 votes |
@SuppressWarnings({"deprecation", "synthetic-access"}) @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) { BluetoothDevice mConnectedHeadset = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); BluetoothClass bluetoothClass = mConnectedHeadset.getBluetoothClass(); if (bluetoothClass != null) { // Check if device is a headset. Besides the 2 below, are there other // device classes also qualified as headset? int deviceClass = bluetoothClass.getDeviceClass(); if (deviceClass == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE || deviceClass == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET) { // start bluetooth Sco audio connection. // Calling startBluetoothSco() always returns faIL here, // that why a count down timer is implemented to call // startBluetoothSco() in the onTick. mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mIsCountDownOn = true; mCountDown.start(); // override this if you want to do other thing when the device is connected. onHeadsetConnected(); } } Log.d(TAG, mConnectedHeadset.getName() + " connected"); } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) { Log.d(TAG, "Headset disconnected"); if (mIsCountDownOn) { mIsCountDownOn = false; mCountDown.cancel(); } mAudioManager.setMode(AudioManager.MODE_NORMAL); // override this if you want to do other thing when the device is disconnected. onHeadsetDisconnected(); } else if (action.equals(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED)) { int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, AudioManager.SCO_AUDIO_STATE_ERROR); if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) { mIsOnHeadsetSco = true; if (mIsStarting) { // When the device is connected before the application starts, // ACTION_ACL_CONNECTED will not be received, so call onHeadsetConnected here mIsStarting = false; onHeadsetConnected(); } if (mIsCountDownOn) { mIsCountDownOn = false; mCountDown.cancel(); } // override this if you want to do other thing when Sco audio is connected. onScoAudioConnected(); Log.d(TAG, "Sco connected"); } else if (state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) { Log.d(TAG, "Sco disconnected"); // Always receive SCO_AUDIO_STATE_DISCONNECTED on call to startBluetooth() // which at that stage we do not want to do anything. Thus the if condition. if (!mIsStarting) { mIsOnHeadsetSco = false; // Need to call stopBluetoothSco(), otherwise startBluetoothSco() // will not be successful. mAudioManager.stopBluetoothSco(); // override this if you want to do other thing when Sco audio is disconnected. onScoAudioDisconnected(); } } } }
Example 5
Source File: BluetoothDeviceView.java From BluetoothHidEmu with Apache License 2.0 | 4 votes |
/** * Checks wether the specified device is a PS3 host. Weirdly enough, the PS3 reports * a device class of 0x2c0108: * * Which means: * - service (0x2c): Rendering | Capturing | Audio * - major # (0x01): Computer * - minor # (0x08): Server-class computer * * This setup seems rather generic for the ps3, however it will have to do for now. * Another option, would be to check the bluetooth MAC prefix, which identifies the * adapter vendor. CECHGxx units seems to be built with Alps Co. adapters (00:1B:FB) * But to check it now could refrain this to work on other unchecked units. * * So, currently we will only check for service/major/minor. * * @param device * @return */ public static boolean isBluetoothDevicePs3(BluetoothDevice device) { if (device == null) { return false; } BluetoothClass bluetoothClass = device.getBluetoothClass(); boolean isPs3 = PS3_MAJOR_MINOR == bluetoothClass.getDeviceClass(); int i = 0; while (isPs3 && i < PS3_SVC_LIST.length) { isPs3 = isPs3 && bluetoothClass.hasService(PS3_SVC_LIST[i]); i++; } return isPs3; }
Example 6
Source File: BluetoothDeviceListAdapter.java From talkback with Apache License 2.0 | 3 votes |
@RequiresPermission(allOf = {permission.BLUETOOTH_ADMIN, permission.BLUETOOTH}) private void setDeviceIconResource(ComparableBluetoothDevice bluetoothDevice) { int imageResource; String description; /* Some bluetooth classes used to determine icon are inaccessible from outside of Android. * Because of this, the icons displayed here may not match the Android settings page exactly. */ BluetoothClass bluetoothClass = bluetoothDevice.getBluetoothClass(); /* Show the default Bluetooth icon if the Bluetooth class is null. */ int majorDeviceClass = (bluetoothClass == null) ? Major.MISC : bluetoothClass.getMajorDeviceClass(); switch (majorDeviceClass) { case Major.COMPUTER: imageResource = R.drawable.ic_bluetooth_computer; description = descriptionManager.computerContentDescription(); break; case Major.PHONE: imageResource = R.drawable.ic_bluetooth_phone; description = descriptionManager.phoneContentDescription(); break; case Major.PERIPHERAL: imageResource = R.drawable.ic_bluetooth_peripheral; description = descriptionManager.peripheralContentDescription(); break; case Major.IMAGING: imageResource = R.drawable.ic_bluetooth_imaging; description = descriptionManager.imagingContentDescription(); break; case Major.AUDIO_VIDEO: // We can't get into this case if bluetoothClass is null because majorDeviceClass would // be Major.MISC not Major.AUDIO_VIDEO. deviceClass is a separate statement to allow // the warning suppression here rather than on the whole method. @SuppressWarnings("nullness:dereference.of.nullable") int deviceClass = bluetoothClass.getDeviceClass(); if (deviceClass == Device.AUDIO_VIDEO_HEADPHONES) { imageResource = R.drawable.ic_bluetooth_headphone; description = descriptionManager.headphoneContentDescription(); break; } // Fall-through default: imageResource = R.drawable.ic_bluetooth_default; description = descriptionManager.defaultBluetoothDeviceContentDescription(); } iconView.setImageResource(imageResource); iconView.setContentDescription(description); }