Code example for BluetoothDevice

Methods: getBluetoothClass, getName

0
            String action = intent.getAction(); 
 
            if (action.equals(BluetoothDevice.ACTION_ACL_CONNECTED)) 
            {        
                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_CALL); 
                        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"); //$NON-NLS-1$ 
            } 
            else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) 
            { 
                Log.d(TAG, "Headset disconnected"); //$NON-NLS-1$