Code example for BluetoothHeadset

Methods: getConnectedDevicesisAudioConnectedstartVoiceRecognition

                    mBluetoothHeadset = (BluetoothHeadset) proxy; 
                    // If a head set is connected before this application starts, 
                    // ACTION_CONNECTION_STATE_CHANGED will not be broadcast.  
                    // So we need to check for already connected head set. 
                    List<BluetoothDevice> devices = mBluetoothHeadset.getConnectedDevices(); 
                    if (devices.size() > 0) 
                        // Only one head set can be connected at a time,  
                        // so the connected head set is at index 0. 
                        mConnectedHeadset = devices.get(0); 
                        String log; 
                        // The audio should not yet be connected at this stage. 
                        // But just to make sure we check. 
                        if (mBluetoothHeadset.isAudioConnected(mConnectedHeadset)) 
                            log = "Profile listener audio already connected"; //$NON-NLS-1$      
                            // The if statement is just for debug. So far startVoiceRecognition always  
                            // returns true here. What can we do if it returns false? Perhaps the only 
                            // sensible thing is to inform the user. 
                            // Well actually, it only returns true if a call to stopVoiceRecognition is 
                            // call somewhere after a call to startVoiceRecognition. Otherwise, if  
                            // stopVoiceRecognition is never called, then when the application is restarted 
                            // startVoiceRecognition always returns false whenever it is called. 
                            if (mBluetoothHeadset.startVoiceRecognition(mConnectedHeadset)) 
                                log = "Profile listener startVoiceRecognition returns true"; 
Contextual code suggestions in your IDE  Get Codota for Java