public int getDeviceClassIcon() { Log.d("TAG", "Device.getDeviceClass() = " + getDeviceClass()); final int deviceClass = getDeviceClass(); final int deviceClassMasked = deviceClass & 0x1F00; if (deviceClass == BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES) { return R.drawable.headphone; } else if (deviceClass == BluetoothClass.Device.AUDIO_VIDEO_MICROPHONE) { return R.drawable.microphone; } else if (deviceClassMasked == BluetoothClass.Device.Major.COMPUTER) { return R.drawable.computer; } else if (deviceClassMasked == BluetoothClass.Device.Major.PHONE) { return R.drawable.cell_phone; } else if (deviceClassMasked == BluetoothClass.Device.Major.HEALTH) { return R.drawable.heart; } else { return R.drawable.bluetooth; } }
/** * Populates the device names and the device addresses with all the suitable * bluetooth devices. * * @param bluetoothAdapter the bluetooth adapter * @param deviceNames list of device names * @param deviceAddresses list of device addresses */ public static void populateDeviceLists( BluetoothAdapter bluetoothAdapter, List<String> deviceNames, List<String> deviceAddresses) { // Ensure the bluetooth adapter is not in discovery mode. bluetoothAdapter.cancelDiscovery(); Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); for (BluetoothDevice device : pairedDevices) { BluetoothClass bluetoothClass = device.getBluetoothClass(); if (bluetoothClass != null) { // Not really sure what we want, but I know what we don't want. switch (bluetoothClass.getMajorDeviceClass()) { case BluetoothClass.Device.Major.COMPUTER: case BluetoothClass.Device.Major.PHONE: break; default: deviceAddresses.add(device.getAddress()); deviceNames.add(device.getName()); } } } }
public boolean isHealthWearable(BluetoothDevice device) { BluetoothClass bluetoothClass = device.getBluetoothClass(); if (bluetoothClass == null) { LOG.warn("unable to determine bluetooth device class of " + device); return false; } if (bluetoothClass.getMajorDeviceClass() == BluetoothClass.Device.Major.WEARABLE || bluetoothClass.getMajorDeviceClass() == BluetoothClass.Device.Major.UNCATEGORIZED) { int deviceClasses = BluetoothClass.Device.HEALTH_BLOOD_PRESSURE | BluetoothClass.Device.HEALTH_DATA_DISPLAY | BluetoothClass.Device.HEALTH_PULSE_RATE | BluetoothClass.Device.HEALTH_WEIGHING | BluetoothClass.Device.HEALTH_UNCATEGORIZED | BluetoothClass.Device.HEALTH_PULSE_OXIMETER | BluetoothClass.Device.HEALTH_GLUCOSE; return (bluetoothClass.getDeviceClass() & deviceClasses) != 0; } return false; }
/** * 扫描枪是否连接 * @return */ public boolean hasScanGun() { if (mBluetoothAdapter == null) { return false; } Set<BluetoothDevice> blueDevices = mBluetoothAdapter.getBondedDevices(); if (blueDevices == null || blueDevices.size() <= 0) { return false; } for (Iterator<BluetoothDevice> iterator = blueDevices.iterator(); iterator.hasNext(); ) { BluetoothDevice bluetoothDevice = iterator.next(); if (bluetoothDevice.getBluetoothClass().getMajorDeviceClass() == BluetoothClass.Device.Major.PERIPHERAL) { mDeviceName = bluetoothDevice.getName(); return isInputDeviceExist(mDeviceName); } } return false; }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (BluetoothDevice.ACTION_FOUND.equals(action)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if ((device.getBondState() != BluetoothDevice.BOND_BONDED) && (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.TOY_ROBOT)) { mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); findViewById(R.id.title_new_devices).setVisibility(View.VISIBLE); findViewById(R.id.no_devices).setVisibility(View.GONE); } } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { setProgressBarIndeterminateVisibility(false); setTitle("Select device"); findViewById(R.id.button_scan).setVisibility(View.VISIBLE); } }
/** * Populates the device names and the device addresses with all the suitable * bluetooth devices. * * @param bluetoothAdapter * the bluetooth adapter * @param deviceNames * list of device names * @param deviceAddresses * list of device addresses */ public static void populateDeviceLists(BluetoothAdapter bluetoothAdapter, List<String> deviceNames, List<String> deviceAddresses) { // Ensure the bluetooth adapter is not in discovery mode. bluetoothAdapter.cancelDiscovery(); Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); for (BluetoothDevice device : pairedDevices) { BluetoothClass bluetoothClass = device.getBluetoothClass(); if (bluetoothClass != null) { // Not really sure what we want, but I know what we don't want. switch (bluetoothClass.getMajorDeviceClass()) { case BluetoothClass.Device.Major.COMPUTER: case BluetoothClass.Device.Major.PHONE: break; default: deviceAddresses.add(device.getAddress()); deviceNames.add(device.getName()); } } } }
public static void getBluetoothDevices(){ BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mBluetoothAdapter.enable(); btDeviceNames = new ArrayList<String>(); Set<BluetoothDevice> a= mBluetoothAdapter.getBondedDevices(); Iterator I=a.iterator(); BluetoothDevice n=null; while(I.hasNext()) { n = (BluetoothDevice) I.next(); BluetoothClass x=n.getBluetoothClass(); if(x!=null){ int xc=x.getDeviceClass(); if((xc==BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO)|| (xc==BluetoothClass.Device.AUDIO_VIDEO_PORTABLE_AUDIO)|| (xc==BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET)|| (xc==BluetoothClass.Device.AUDIO_VIDEO_LOUDSPEAKER)) { String k = n.getName(); btDeviceNames.add(k); } } } }
private boolean isContainBTHeadphone(BluetoothAdapter mBluetoothAdapter) { Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); // If there are paired devices if (pairedDevices.size() > 0) { // Loop through paired devices for (BluetoothDevice device : pairedDevices) { if (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO) { return true; } else if (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE) { return true; } else if (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES) { return true; } else if (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.AUDIO_VIDEO_LOUDSPEAKER) { return true; } else if (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET) { return true; } } } return false; }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); View view = inflater.inflate(R.layout.view_add_bluetooth_server, container); ListView listViewBtPairedPCs = (ListView) view.findViewById(R.id.listViewBtPairedPCs); ArrayList<BluetoothDevice> pairedBluetoothList = new ArrayList<>(); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); if (pairedDevices.size() > 0) { for (BluetoothDevice device : pairedDevices) { if(device.getBluetoothClass().getMajorDeviceClass() == BluetoothClass.Device.Major.COMPUTER) { pairedBluetoothList.add(device); } } if (pairedBluetoothList.size() == 0) { Toast.makeText(getActivity().getApplicationContext(), R.string.bluetooth_no_paired_found, Toast.LENGTH_LONG).show(); return null; } } else { Toast.makeText(getActivity().getApplicationContext(), R.string.bluetooth_no_paired_found, Toast.LENGTH_LONG).show(); return null; } BluetoothPairedDevicesAdapter adapter = new BluetoothPairedDevicesAdapter(getActivity(), pairedBluetoothList, this); listViewBtPairedPCs.setAdapter(adapter); return view; }
private void onDeviceFound(BluetoothDevice device) { if (device != null && device.getName() != null && (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.COMPUTER_HANDHELD_PC_PDA || device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.COMPUTER_PALM_SIZE_PC_PDA || device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.PHONE_SMART)) { subscriber.onNext(new BluetoothPeer(device)); } }
@Override public void onReceive(Context context, Intent intent) { if (intent == null) return; Log.w(TAG, "onReceive"); synchronized (LOCK) { if (getScoChangeIntent().equals(intent.getAction())) { int status = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, AudioManager.SCO_AUDIO_STATE_ERROR); if (status == AudioManager.SCO_AUDIO_STATE_CONNECTED) { if (Build.VERSION.SDK_INT >= 11 && bluetoothHeadset != null) { List<BluetoothDevice> devices = bluetoothHeadset.getConnectedDevices(); for (BluetoothDevice device : devices) { if (bluetoothHeadset.isAudioConnected(device)) { int deviceClass = device.getBluetoothClass().getDeviceClass(); if (deviceClass == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE || deviceClass == BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO || deviceClass == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET) { scoConnection = ScoConnection.CONNECTED; if (wantsConnection) { AudioManager audioManager = ServiceUtil.getAudioManager(context); audioManager.setBluetoothScoOn(true); } } } } } } } } handleBluetoothStateChange(); }
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; }
public boolean foundDevice (BluetoothDevice device) { boolean resultIsNew = false; if (device != null && device.getName() != null && (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.COMPUTER_HANDHELD_PC_PDA || device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.COMPUTER_PALM_SIZE_PC_PDA || device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.PHONE_SMART)) { if (mPairedDevicesOnly && device.getBondState() == BluetoothDevice.BOND_NONE) return false; //we can only support paired devices if (!mFoundDevices.containsKey(device.getAddress())) { mFoundDevices.put(device.getAddress(), device); resultIsNew = true; if (mNearbyListener != null) { Neighbor neighbor = new Neighbor(device.getAddress(),device.getName(),Neighbor.TYPE_BLUETOOTH); mNearbyListener.foundNeighbor(neighbor); } } if (clientThreads.containsKey(device.getAddress())) if (clientThreads.get(device.getAddress()).isAlive()) return false; //we have a running thread here people! log("Found device: " + device.getName() + ":" + device.getAddress()); ClientThread clientThread = new ClientThread(device, mHandler, mPairedDevicesOnly); clientThread.start(); clientThreads.put(device.getAddress(), clientThread); } return resultIsNew; }
public static String resolveMajorDeviceClass(final int majorBtClass) { switch (majorBtClass) { case BluetoothClass.Device.Major.AUDIO_VIDEO: return "Audio/ Video"; case BluetoothClass.Device.Major.COMPUTER: return "Computer"; case BluetoothClass.Device.Major.HEALTH: return "Health"; case BluetoothClass.Device.Major.IMAGING: return "Imaging"; case BluetoothClass.Device.Major.MISC: return "Misc"; case BluetoothClass.Device.Major.NETWORKING: return "Networking"; case BluetoothClass.Device.Major.PERIPHERAL: return "Peripheral"; case BluetoothClass.Device.Major.PHONE: return "Phone"; case BluetoothClass.Device.Major.TOY: return "Toy"; case BluetoothClass.Device.Major.UNCATEGORIZED: return "Uncategorized"; case BluetoothClass.Device.Major.WEARABLE: return "Wearable"; default: return "Unknown (" +majorBtClass+ ")"; } }
@Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { String name = device.getName(); BluetoothClass bluetoothClass = device.getBluetoothClass(); String address = device.getAddress(); int type = device.getType(); ParcelUuid[] uuids = device.getUuids(); StringBuilder deviceInfo = new StringBuilder(); deviceInfo.append(name + " - " + bluetoothClass + " (" + address + ',' + type + ") ["); if (uuids != null) { for (ParcelUuid uuid : uuids) { deviceInfo.append(uuid).append(", "); } } deviceInfo.append(']'); LOGGER.info("Found Bluetooth device '" + deviceInfo + "' with rssi " + rssi); if (name == null || !name.startsWith("Polar H7")) return; MainActivity.withMainActivity((ma) -> { Toast.makeText(ma, "Found Polar H7 device, trying to discover services", Toast.LENGTH_SHORT).show(); }); stopBleDeviceDiscovery(); device.connectGatt(mContext, true, mBluetoothGattCallback); }
public static String resolveMajorDeviceClass(final int majorBtClass) { switch (majorBtClass) { case BluetoothClass.Device.Major.AUDIO_VIDEO: return "Audio/ Video"; case BluetoothClass.Device.Major.COMPUTER: return "Computer"; case BluetoothClass.Device.Major.HEALTH: return "Health"; case BluetoothClass.Device.Major.IMAGING: return "Imaging"; case BluetoothClass.Device.Major.MISC: return "Misc"; case BluetoothClass.Device.Major.NETWORKING: return "Networking"; case BluetoothClass.Device.Major.PERIPHERAL: return "Peripheral"; case BluetoothClass.Device.Major.PHONE: return "Phone"; case BluetoothClass.Device.Major.TOY: return "Toy"; case BluetoothClass.Device.Major.UNCATEGORIZED: return "Uncategorized"; case BluetoothClass.Device.Major.WEARABLE: return "Wearable"; default: return "Unknown (" + majorBtClass + ")"; } }
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(); }
@JavascriptInterface public String getDevices() { boolean added = populatePairedDevices(); JSONArray devices = new JSONArray(); for (GobbedDevice gdev: mDeviceList.values()) { JSONObject j = new JSONObject(); try { String s = gdev.btDev.getName(); if (s != null) j.put("name", s); s = gdev.btDev.getAddress(); if (s != null) j.put("address", s); j.put("paired", gdev.isPaired); if (gdev.isPaired) { j.put("connected", gdev.isConnected); j.put("connecting", gdev.isConnecting); j.put("connectable", gdev.isConnectable); } BluetoothClass devclass = gdev.btDev.getBluetoothClass(); if (devclass != null) j.put("deviceClass", devclass.getDeviceClass()); JSONArray uuids = new JSONArray(); // If you have never attempted to pair or connect with dev before, getUuids() will // return null (no uuids in cache). if (Build.VERSION.SDK_INT >= 15 && gdev.btDev.getUuids() != null) { // API 15: Icecream MR1 for (ParcelUuid uuid : gdev.btDev.getUuids()) { uuids.put(uuid.toString()); } } j.put("uuids", uuids); } catch (JSONException e) { // Must never happen. put(String, bool) may only throw if: // 1. key is null - the above code will never have a null key. // 2. testValidity() throws for a String. throw new RuntimeException("JSONException for put(non-null String, String)", e); } devices.put(j); } return devices.toString(); }
public static SubjectFactory<BluetoothClassSubject, BluetoothClass> type() { return new SubjectFactory<BluetoothClassSubject, BluetoothClass>() { @Override public BluetoothClassSubject getSubject(FailureStrategy fs, BluetoothClass that) { return new BluetoothClassSubject(fs, that); } }; }
public static String majorDeviceClassToString(int majorDeviceClass) { return buildNamedValueString(majorDeviceClass) .value(BluetoothClass.Device.Major.AUDIO_VIDEO, "audio_video") .value(BluetoothClass.Device.Major.COMPUTER, "computer") .value(BluetoothClass.Device.Major.HEALTH, "health") .value(BluetoothClass.Device.Major.IMAGING, "imaging") .value(BluetoothClass.Device.Major.MISC, "misc") .value(BluetoothClass.Device.Major.NETWORKING, "networking") .value(BluetoothClass.Device.Major.PERIPHERAL, "peripheral") .value(BluetoothClass.Device.Major.PHONE, "phone") .value(BluetoothClass.Device.Major.TOY, "toy") .value(BluetoothClass.Device.Major.UNCATEGORIZED, "uncategorized") .value(BluetoothClass.Device.Major.WEARABLE, "wearable") .get(); }
public static String serviceToString(int service) { return buildNamedValueString(service) .value(BluetoothClass.Service.AUDIO, "audio") .value(BluetoothClass.Service.CAPTURE, "capture") .value(BluetoothClass.Service.INFORMATION, "information") .value(BluetoothClass.Service.LIMITED_DISCOVERABILITY, "limited_discoverability") .value(BluetoothClass.Service.NETWORKING, "networking") .value(BluetoothClass.Service.OBJECT_TRANSFER, "object_transfer") .value(BluetoothClass.Service.POSITIONING, "positioning") .value(BluetoothClass.Service.RENDER, "render") .value(BluetoothClass.Service.TELEPHONY, "telephony") .get(); }
private void onDeviceFound(BluetoothDevice device) { if (device != null && device.getName() != null && (device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.COMPUTER_HANDHELD_PC_PDA || device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.COMPUTER_PALM_SIZE_PC_PDA || device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.PHONE_SMART)) { foundPeer(new BluetoothPeer(device)); } }
private boolean checkPrinter(BluetoothDevice device) { if(device==null) return false; BluetoothClass btcls = device.getBluetoothClass(); if(btcls==null) return false; return PrinterConst.BTPrinterClasses.equals(btcls.toString()); }
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(BluetoothClass.Service.RENDER) || deviceClass == BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET || deviceClass == BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO || deviceClass == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE) { //And if any can be used as a audio handset hasConnectedDevice = true; break; } } } } boolean retVal = hasConnectedDevice && audioManager.isBluetoothScoAvailableOffCall(); Log.d(TAG, "Can I do BT ? " + retVal); return retVal; }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { holder = new Holder(); convertView = LayoutInflater.from(context).inflate( R.layout.item_bluetooth, null); holder.name = (TextView) convertView .findViewById(R.id.item_bluetooth_name); holder.icon = (ImageView) convertView .findViewById(R.id.item_bluetooth_iv); convertView.setTag(holder); } else { holder = (Holder) convertView.getTag(); } Map<String,Object> map = list.get(position); String name = (String) map.get("name"); if(name != null){ holder.name.setText((String) map.get("name")); } int type = (Integer)map.get("type"); //根据设备类型 设置相应图片 if(type> BluetoothClass.Device.PHONE_UNCATEGORIZED&&type<BluetoothClass.Device.PHONE_ISDN){ holder.icon.setBackgroundResource(R.drawable.phone); }else if(type> BluetoothClass.Device.COMPUTER_UNCATEGORIZED&&type<BluetoothClass.Device.COMPUTER_WEARABLE){ holder.icon.setBackgroundResource(R.drawable.pc); }else if(type> BluetoothClass.Device.TOY_UNCATEGORIZED&&type<BluetoothClass.Device.TOY_GAME){ holder.icon.setBackgroundResource(R.drawable.handle); } return convertView; }
public static boolean isAvailable() { if (!ba.isEnabled()) return false; Set<BluetoothDevice> devs = ba.getBondedDevices(); for (final BluetoothDevice dev : devs) { BluetoothClass cl = dev.getBluetoothClass(); if (cl != null && (cl.hasService(Service.RENDER) || cl.getDeviceClass() == Device.AUDIO_VIDEO_HANDSFREE || cl.getDeviceClass() == Device.AUDIO_VIDEO_CAR_AUDIO || cl.getDeviceClass() == Device.AUDIO_VIDEO_WEARABLE_HEADSET)) return true; } return false; }
public CharSequence getMsg() { StringBuilder sb = new StringBuilder(); // MACアドレス sb.append("address: " + mBluetoothDevice.getAddress() + "\n"); // デバイスクラス // 電波強度が分かるらしい。 // http://ja.wikipedia.org/wiki/Bluetooth#.E3.82.AF.E3.83.A9.E3.82.B9 BluetoothClass bluetoothClass = mBluetoothDevice.getBluetoothClass(); int majoreClass = mBluetoothDevice.getBluetoothClass().getMajorDeviceClass() >> 8; int minorClass = mBluetoothDevice.getBluetoothClass().getDeviceClass() & 0xFF; sb.append("majore class: " + majoreClass + "\n"); sb.append("minor class: " + minorClass + "\n"); // 接続状態 CharSequence bondStateStr; switch (mBluetoothDevice.getBondState()) { case BluetoothDevice.BOND_BONDING: bondStateStr = "接続中"; break; case BluetoothDevice.BOND_BONDED: bondStateStr = "接続履歴あり"; break; case BluetoothDevice.BOND_NONE: bondStateStr = "新規デバイス"; break; default: bondStateStr = "接続状態不明"; break; } sb.append("bond state: " + bondStateStr + "\n"); return sb.toString(); }
private boolean existBluetoothHeadset() { for (BluetoothDevice dispositivo: bluetoothAdapter.getBondedDevices()) { BluetoothClass clase= dispositivo.getBluetoothClass(); switch (clase.getDeviceClass()) { case BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES: return true; case BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET: return true; case BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE: return true; } } return false; }
@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(); } }
public static String majorDeviceClassToString(int majorDeviceClass) { return buildNamedValueString(majorDeviceClass) // .value(BluetoothClass.Device.Major.AUDIO_VIDEO, "audio_video") .value(BluetoothClass.Device.Major.COMPUTER, "computer") .value(BluetoothClass.Device.Major.HEALTH, "health") .value(BluetoothClass.Device.Major.IMAGING, "imaging") .value(BluetoothClass.Device.Major.MISC, "misc") .value(BluetoothClass.Device.Major.NETWORKING, "networking") .value(BluetoothClass.Device.Major.PERIPHERAL, "peripheral") .value(BluetoothClass.Device.Major.PHONE, "phone") .value(BluetoothClass.Device.Major.TOY, "toy") .value(BluetoothClass.Device.Major.UNCATEGORIZED, "uncategorized") .value(BluetoothClass.Device.Major.WEARABLE, "wearable") .get(); }
public static String serviceToString(int service) { return buildNamedValueString(service) // .value(BluetoothClass.Service.AUDIO, "audio") .value(BluetoothClass.Service.CAPTURE, "capture") .value(BluetoothClass.Service.INFORMATION, "information") .value(BluetoothClass.Service.LIMITED_DISCOVERABILITY, "limited_discoverability") .value(BluetoothClass.Service.NETWORKING, "networking") .value(BluetoothClass.Service.OBJECT_TRANSFER, "object_transfer") .value(BluetoothClass.Service.POSITIONING, "positioning") .value(BluetoothClass.Service.RENDER, "render") .value(BluetoothClass.Service.TELEPHONY, "telephony") .get(); }
protected BluetoothClassSubject(FailureStrategy failureStrategy, BluetoothClass subject) { super(failureStrategy, subject); }
public static String deviceClassToString(int deviceClass) { return buildNamedValueString(deviceClass) .value(BluetoothClass.Device.AUDIO_VIDEO_CAMCORDER, "AUDIO_VIDEO_CAMCORDER") .value(BluetoothClass.Device.AUDIO_VIDEO_CAR_AUDIO, "AUDIO_VIDEO_CAR_AUDIO") .value(BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE, "AUDIO_VIDEO_HANDSFREE") .value(BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES, "AUDIO_VIDEO_HEADPHONES") .value(BluetoothClass.Device.AUDIO_VIDEO_HIFI_AUDIO, "AUDIO_VIDEO_HIFI_AUDIO") .value(BluetoothClass.Device.AUDIO_VIDEO_LOUDSPEAKER, "AUDIO_VIDEO_LOUDSPEAKER") .value(BluetoothClass.Device.AUDIO_VIDEO_MICROPHONE, "AUDIO_VIDEO_MICROPHONE") .value(BluetoothClass.Device.AUDIO_VIDEO_PORTABLE_AUDIO, "AUDIO_VIDEO_PORTABLE_AUDIO") .value(BluetoothClass.Device.AUDIO_VIDEO_SET_TOP_BOX, "AUDIO_VIDEO_SET_TOP_BOX") .value(BluetoothClass.Device.AUDIO_VIDEO_UNCATEGORIZED, "AUDIO_VIDEO_UNCATEGORIZED") .value(BluetoothClass.Device.AUDIO_VIDEO_VCR, "AUDIO_VIDEO_VCR") .value(BluetoothClass.Device.AUDIO_VIDEO_VIDEO_CAMERA, "AUDIO_VIDEO_VIDEO_CAMERA") .value(BluetoothClass.Device.AUDIO_VIDEO_VIDEO_CONFERENCING, "AUDIO_VIDEO_VIDEO_CONFERENCING") .value(BluetoothClass.Device.AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER, "AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER") .value(BluetoothClass.Device.AUDIO_VIDEO_VIDEO_GAMING_TOY, "AUDIO_VIDEO_VIDEO_GAMING_TOY") .value(BluetoothClass.Device.AUDIO_VIDEO_VIDEO_MONITOR, "AUDIO_VIDEO_VIDEO_MONITOR") .value(BluetoothClass.Device.AUDIO_VIDEO_WEARABLE_HEADSET, "AUDIO_VIDEO_WEARABLE_HEADSET") .value(BluetoothClass.Device.COMPUTER_DESKTOP, "COMPUTER_DESKTOP") .value(BluetoothClass.Device.COMPUTER_HANDHELD_PC_PDA, "COMPUTER_HANDHELD_PC_PDA") .value(BluetoothClass.Device.COMPUTER_LAPTOP, "COMPUTER_LAPTOP") .value(BluetoothClass.Device.COMPUTER_PALM_SIZE_PC_PDA, "COMPUTER_PALM_SIZE_PC_PDA") .value(BluetoothClass.Device.COMPUTER_SERVER, "COMPUTER_SERVER") .value(BluetoothClass.Device.COMPUTER_UNCATEGORIZED, "COMPUTER_UNCATEGORIZED") .value(BluetoothClass.Device.COMPUTER_WEARABLE, "COMPUTER_WEARABLE") .value(BluetoothClass.Device.HEALTH_BLOOD_PRESSURE, "HEALTH_BLOOD_PRESSURE") .value(BluetoothClass.Device.HEALTH_DATA_DISPLAY, "HEALTH_DATA_DISPLAY") .value(BluetoothClass.Device.HEALTH_GLUCOSE, "HEALTH_GLUCOSE") .value(BluetoothClass.Device.HEALTH_PULSE_OXIMETER, "HEALTH_PULSE_OXIMETER") .value(BluetoothClass.Device.HEALTH_PULSE_RATE, "HEALTH_PULSE_RATE") .value(BluetoothClass.Device.HEALTH_THERMOMETER, "HEALTH_THERMOMETER") .value(BluetoothClass.Device.HEALTH_UNCATEGORIZED, "HEALTH_UNCATEGORIZED") .value(BluetoothClass.Device.HEALTH_WEIGHING, "HEALTH_WEIGHING") .value(BluetoothClass.Device.PHONE_CELLULAR, "PHONE_CELLULAR") .value(BluetoothClass.Device.PHONE_CORDLESS, "PHONE_CORDLESS") .value(BluetoothClass.Device.PHONE_ISDN, "PHONE_ISDN") .value(BluetoothClass.Device.PHONE_MODEM_OR_GATEWAY, "PHONE_MODEM_OR_GATEWAY") .value(BluetoothClass.Device.PHONE_SMART, "PHONE_SMART") .value(BluetoothClass.Device.PHONE_UNCATEGORIZED, "PHONE_UNCATEGORIZED") .value(BluetoothClass.Device.TOY_CONTROLLER, "TOY_CONTROLLER") .value(BluetoothClass.Device.TOY_DOLL_ACTION_FIGURE, "TOY_DOLL_ACTION_FIGURE") .value(BluetoothClass.Device.TOY_GAME, "TOY_GAME") .value(BluetoothClass.Device.TOY_ROBOT, "TOY_ROBOT") .value(BluetoothClass.Device.TOY_UNCATEGORIZED, "TOY_UNCATEGORIZED") .value(BluetoothClass.Device.TOY_VEHICLE, "TOY_VEHICLE") .value(BluetoothClass.Device.WEARABLE_GLASSES, "WEARABLE_GLASSES") .value(BluetoothClass.Device.WEARABLE_HELMET, "WEARABLE_HELMET") .value(BluetoothClass.Device.WEARABLE_JACKET, "WEARABLE_JACKET") .value(BluetoothClass.Device.WEARABLE_PAGER, "WEARABLE_PAGER") .value(BluetoothClass.Device.WEARABLE_UNCATEGORIZED, "WEARABLE_UNCATEGORIZED") .value(BluetoothClass.Device.WEARABLE_WRIST_WATCH, "WEARABLE_WRIST_WATCH") .get(); }
public BluetoothClass getBluetoothClass() { return mDevice.getBluetoothClass(); }