Android BluetoothHeadset - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android BluetoothHeadset class.

This code example shows how to use the following methods:getConnectedDevices, getConnectionState
        } 
    } 
 
    public int getConnectionStatus(BluetoothDevice device) {
        if (mService == null) return BluetoothProfile.STATE_DISCONNECTED;
        List<BluetoothDevice> deviceList = mService.getConnectedDevices();
 
        return !deviceList.isEmpty() && deviceList.get(0).equals(device)
                ? mService.getConnectionState(device)
                : BluetoothProfile.STATE_DISCONNECTED;
    } 
 
    public boolean isPreferred(BluetoothDevice device) {
        if (mService == null) return false;
        return mService.getPriority(device) > BluetoothProfile.PRIORITY_OFF;
    } 
 
    public int getPreferred(BluetoothDevice device) {
        if (mService == null) return BluetoothProfile.PRIORITY_OFF;
        return mService.getPriority(device);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConnectedDevices, startVoiceRecognition, stopVoiceRecognition
            btAdapter.closeProfileProxy(BluetoothProfile.HEADSET, bluetoothHeadset);
        } 
    } 
 
    public void startVoiceRecognition() { 
        BluetoothDevice btDevice = bluetoothHeadset.getConnectedDevices().get(0);
        bluetoothHeadset.stopVoiceRecognition(btDevice);
        bluetoothHeadset.startVoiceRecognition(btDevice);
    } 
     
    public void stopVoiceRecognition() { 
        BluetoothDevice btDevice = bluetoothHeadset.getConnectedDevices().get(0);
        bluetoothHeadset.stopVoiceRecognition(btDevice); 
    } 
 
    public boolean isAvailable() { 
        return bluetoothHeadset != null && bluetoothHeadset.getConnectedDevices().size() > 0;
    } 
     
    public VOICE getVoiceState() { 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConnectedDevices, isAudioConnected, startVoiceRecognition
                    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$      
                        } 

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConnectedDevices, getConnectionState
				if ( mBluetoothAdapter.isEnabled() == false || mBluetoothHeadset == null ) {
					returnNow = true;
					logMessage = "onHandleIntent/closeProfileProxy/During waiting for answering, BT may be disabled.";
				} 
				else { 
					btDevices = mBluetoothHeadset.getConnectedDevices();
					if ( btDevices.isEmpty() ) {
						returnNow = true;
						logMessage = "onHandleIntent/closeProfileProxy/No connected BT devices.";
					} 
					else if ( mBluetoothHeadset.getConnectionState(btDevices.get(0)) != BluetoothProfile.STATE_CONNECTED)  {
						returnNow = true;
						logMessage = "onHandleIntent/closeProfileProxy/No connected headset.";
					} 
				} 
				 
				mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
				 
				if( returnNow ) {
					Log.d(TAG, logMessage);
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConnectedDevices, getConnectionState
        } 
    } 
 
    public int getConnectionStatus(BluetoothDevice device) {
        if (mService == null) return BluetoothProfile.STATE_DISCONNECTED;
        List<BluetoothDevice> deviceList = mService.getConnectedDevices();
 
        return !deviceList.isEmpty() && deviceList.get(0).equals(device)
                ? mService.getConnectionState(device)
                : BluetoothProfile.STATE_DISCONNECTED;
    } 
 
    public boolean isPreferred(BluetoothDevice device) {
        if (mService == null) return false;
        return mService.getPriority(device) > BluetoothProfile.PRIORITY_OFF;
    } 
 
    public int getPreferred(BluetoothDevice device) {
        if (mService == null) return BluetoothProfile.PRIORITY_OFF;
        return mService.getPriority(device);
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:startVoiceRecognition
		if( device != null ){
			Log.e("MY BLUETOOTH", "Connecting Device");
			 // Use a temporary object that is later assigned to mmSocket, 
	        // because mmSocket is final 
	        //BluetoothSocket socket = null; 
			headset.startVoiceRecognition(device);
	        //startVoiceRecognition(device); 
	        // Get a BluetoothSocket to connect with the given BluetoothDevice 
//	        try { 
//	            // MY_UUID is the app's UUID string, also used by the server code 
//	            socket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID); 
//	        } catch (IOException e) {Log.e("MY BLUETOOTH", "Hooking device to socket failed"); } 
//	         
//	        btAdapter.cancelDiscovery(); 
//	         
//	        try { 
//	            // Connect the device through the socket. This will block 
//	            // until it succeeds or throws an exception 
//	            socket.connect(); 
//	            Log.e("MY BLUETOOTH", "Connection successful"); 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConnectedDevices
        filter.addAction(ACTION_DENY_CONNECT);
 
        mContext.registerReceiver(mReceiver, filter);
 
        if (mA2dp.getConnectedDevices().contains(mDevice) ||
                mHeadset.getConnectedDevices().contains(mDevice)) {
            Log.i(TAG, "ACTION_DISCONNECT addr=" + mDevice + " name=" + mName);
            mAction = ACTION_DISCONNECT;
        } else { 
            Log.i(TAG, "ACTION_CONNECT addr=" + mDevice + " name=" + mName);
            mAction = ACTION_CONNECT;
        } 
        mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_TIMEOUT), TIMEOUT_MS);
        nextStep(); 
    } 
 
    /** 
     * Called to execute next step in state machine 
     */ 
    void nextStep() { 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConnectedDevices
        filter.addAction(ACTION_DENY_CONNECT);
 
        mContext.registerReceiver(mReceiver, filter);
 
        if (mA2dp.getConnectedDevices().contains(mDevice) ||
                mHeadset.getConnectedDevices().contains(mDevice)) {
            Log.i(TAG, "ACTION_DISCONNECT addr=" + mDevice + " name=" + mName);
            mAction = ACTION_DISCONNECT;
        } else { 
            Log.i(TAG, "ACTION_CONNECT addr=" + mDevice + " name=" + mName);
            mAction = ACTION_CONNECT;
        } 
        mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_TIMEOUT), TIMEOUT_MS);
        nextStep(); 
    } 
 
    /** 
     * Called to execute next step in state machine 
     */ 
    void nextStep() { 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getConnectedDevices
        public void onServiceConnected(int profile, BluetoothProfile proxy) {
            if (V) Log.d(TAG,"Bluetooth service connected");
            mService = (BluetoothHeadset) proxy;
            // We just bound to the service, so refresh the UI of the 
            // headset device. 
            List<BluetoothDevice> deviceList = mService.getConnectedDevices();
            if (!deviceList.isEmpty()) {
                BluetoothDevice firstDevice = deviceList.get(0);
                CachedBluetoothDevice device = mDeviceManager.findDevice(firstDevice);
                // we may add a new device here, but generally this should not happen 
                if (device == null) {
                    Log.w(TAG, "HeadsetProfile found new device: " + firstDevice);
                    device = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, firstDevice);
                } 
                device.onProfileStateChanged(HeadsetProfile.this,
                        BluetoothProfile.STATE_CONNECTED);
            } 
 
            mProfileManager.callServiceConnectedListeners();
            mIsProfileReady=true;
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:stopVoiceRecognition
                { 
                    if (mBluetoothHeadset != null) 
                    { 
                        // Need to call stopVoiceRecognition here when the app 
                        // change orientation or close with headset still turns on. 
                         mBluetoothHeadset.stopVoiceRecognition(mConnectedHeadset); 
                         unregisterReceiver(mHeadsetBroadcastReceiver); 
                         mCountDown.cancel(); 
                    } 
                    mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset); 
                } 
                Log.d(TAG, "onDestroy"); //$NON-NLS-1$ 
            } 
 
            @SuppressLint("NewApi") 
			protected BluetoothProfile.ServiceListener mHeadsetProfileListener = new BluetoothProfile.ServiceListener() 
            { 
 
                /** 
                 * This method is never called, even when we closeProfileProxy on onPause. 
4
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android BluetoothHeadset Questions & Answers:

See Code Examples for Android BluetoothHeadset Methods: