Java Code Examples for android.bluetooth.BluetoothProfile#HEADSET
The following examples show how to use
android.bluetooth.BluetoothProfile#HEADSET .
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: BluetoothManager.java From Linphone4Android with GNU General Public License v3.0 | 9 votes |
private void startBluetooth() { if (isBluetoothConnected) { Log.e("[Bluetooth] Already started, skipping..."); return; } mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) { if (mProfileListener != null) { Log.w("[Bluetooth] Headset profile was already opened, let's close it"); mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset); } mProfileListener = new BluetoothProfile.ServiceListener() { public void onServiceConnected(int profile, BluetoothProfile proxy) { if (profile == BluetoothProfile.HEADSET) { Log.d("[Bluetooth] Headset connected"); mBluetoothHeadset = (BluetoothHeadset) proxy; isBluetoothConnected = true; } } public void onServiceDisconnected(int profile) { if (profile == BluetoothProfile.HEADSET) { mBluetoothHeadset = null; isBluetoothConnected = false; Log.d("[Bluetooth] Headset disconnected"); LinphoneManager.getInstance().routeAudioToReceiver(); } } }; boolean success = mBluetoothAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.HEADSET); if (!success) { Log.e("[Bluetooth] getProfileProxy failed !"); } } else { Log.w("[Bluetooth] Interface disabled on device"); } }
Example 2
Source File: BtManager.java From apollo-DuerOS with Apache License 2.0 | 6 votes |
@Override public void onServiceConnected(int profile, BluetoothProfile proxy) { LogUtil.i(TAG, "onServiceConnected"); if (profile == BluetoothProfile.HEADSET) { List<BluetoothDevice> connectedDevices = proxy.getConnectedDevices(); for (BluetoothDevice bluetoothDevice : connectedDevices) { if (bluetoothDevice == null) { continue; } String address = bluetoothDevice.getAddress(); if (address != null && address.equals(mRemoteBTAddress)) { CarlifeBTPairInfo buildBluetoothInfo = BtManager.getInstance().buildBluetoothInfo(BLUETOOTH_STATUS_ALREADY_CONNECTED); if (buildBluetoothInfo != null) { BtManager.getInstance().sendBluetoothInfoToMd(buildBluetoothInfo); } } } } }
Example 3
Source File: BluetoothManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean bindBluetoothProfileService(int bluetoothProfile, IBluetoothProfileServiceConnection proxy) { if (!mEnable) { if (DBG) { Slog.d(TAG, "Trying to bind to profile: " + bluetoothProfile + ", while Bluetooth was disabled"); } return false; } synchronized (mProfileServices) { ProfileServiceConnections psc = mProfileServices.get(new Integer(bluetoothProfile)); if (psc == null) { if (DBG) { Slog.d(TAG, "Creating new ProfileServiceConnections object for" + " profile: " + bluetoothProfile); } if (bluetoothProfile != BluetoothProfile.HEADSET) { return false; } Intent intent = new Intent(IBluetoothHeadset.class.getName()); psc = new ProfileServiceConnections(intent); if (!psc.bindService()) { return false; } mProfileServices.put(new Integer(bluetoothProfile), psc); } } // Introducing a delay to give the client app time to prepare Message addProxyMsg = mHandler.obtainMessage(MESSAGE_ADD_PROXY_DELAYED); addProxyMsg.arg1 = bluetoothProfile; addProxyMsg.obj = proxy; mHandler.sendMessageDelayed(addProxyMsg, ADD_PROXY_DELAY_MS); return true; }
Example 4
Source File: AppRTCBluetoothManager.java From imsdk-android with MIT License | 5 votes |
@Override // Called to notify the client when the proxy object has been connected to the service. // Once we have the profile proxy object, we can use it to monitor the state of the // connection and perform other operations that are relevant to the headset profile. public void onServiceConnected(int profile, BluetoothProfile proxy) { if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { return; } LogUtil.d(TAG, "BluetoothServiceListener.onServiceConnected: BT state=" + bluetoothState); // Android only supports one connected Bluetooth Headset at a time. bluetoothHeadset = (BluetoothHeadset) proxy; updateAudioDeviceState(); LogUtil.d(TAG, "onServiceConnected done: BT state=" + bluetoothState); }
Example 5
Source File: AppRTCBluetoothManager.java From imsdk-android with MIT License | 5 votes |
@Override /** Notifies the client when the proxy object has been disconnected from the service. */ public void onServiceDisconnected(int profile) { if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { return; } LogUtil.d(TAG, "BluetoothServiceListener.onServiceDisconnected: BT state=" + bluetoothState); stopScoAudio(); bluetoothHeadset = null; bluetoothDevice = null; bluetoothState = State.HEADSET_UNAVAILABLE; updateAudioDeviceState(); LogUtil.d(TAG, "onServiceDisconnected done: BT state=" + bluetoothState); }
Example 6
Source File: AppRTCBluetoothManager.java From flutter-incall-manager with ISC License | 5 votes |
@Override // Called to notify the client when the proxy object has been connected to the service. // Once we have the profile proxy object, we can use it to monitor the state of the // connection and perform other operations that are relevant to the headset profile. public void onServiceConnected(int profile, BluetoothProfile proxy) { if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { return; } Log.d(TAG, "BluetoothServiceListener.onServiceConnected: BT state=" + bluetoothState); // Android only supports one connected Bluetooth Headset at a time. bluetoothHeadset = (BluetoothHeadset) proxy; updateAudioDeviceState(); Log.d(TAG, "onServiceConnected done: BT state=" + bluetoothState); }
Example 7
Source File: AppRTCBluetoothManager.java From flutter-incall-manager with ISC License | 5 votes |
@Override /** Notifies the client when the proxy object has been disconnected from the service. */ public void onServiceDisconnected(int profile) { if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { return; } Log.d(TAG, "BluetoothServiceListener.onServiceDisconnected: BT state=" + bluetoothState); stopScoAudio(); bluetoothHeadset = null; bluetoothDevice = null; bluetoothState = State.HEADSET_UNAVAILABLE; updateAudioDeviceState(); Log.d(TAG, "onServiceDisconnected done: BT state=" + bluetoothState); }
Example 8
Source File: AssistantService.java From AssistantBySDK with Apache License 2.0 | 5 votes |
@Override public void onServiceDisconnected(int profile) { Log.e("blueHeadsetListener", "onServiceDisconnected:" + profile); if (profile == BluetoothProfile.A2DP) { voiceMediator.setBluetoothA2dp(null); } else if (profile == BluetoothProfile.HEADSET) { voiceMediator.setBluetoothHeadset(null); } }
Example 9
Source File: AssistantService.java From AssistantBySDK with Apache License 2.0 | 5 votes |
@Override public void onServiceConnected(int profile, BluetoothProfile proxy) { Log.e("blueHeadsetListener", "onServiceConnected:" + profile); if (profile == BluetoothProfile.A2DP) { voiceMediator.setBluetoothA2dp((BluetoothA2dp) proxy); } else if (profile == BluetoothProfile.HEADSET) { voiceMediator.setBluetoothHeadset((BluetoothHeadset) proxy); } }
Example 10
Source File: AppRTCBluetoothManager.java From react-native-incall-manager with ISC License | 5 votes |
@Override // Called to notify the client when the proxy object has been connected to the service. // Once we have the profile proxy object, we can use it to monitor the state of the // connection and perform other operations that are relevant to the headset profile. public void onServiceConnected(int profile, BluetoothProfile proxy) { if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { return; } Log.d(TAG, "BluetoothServiceListener.onServiceConnected: BT state=" + bluetoothState); // Android only supports one connected Bluetooth Headset at a time. bluetoothHeadset = (BluetoothHeadset) proxy; updateAudioDeviceState(); Log.d(TAG, "onServiceConnected done: BT state=" + bluetoothState); }
Example 11
Source File: AppRTCBluetoothManager.java From react-native-incall-manager with ISC License | 5 votes |
@Override /** Notifies the client when the proxy object has been disconnected from the service. */ public void onServiceDisconnected(int profile) { if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { return; } Log.d(TAG, "BluetoothServiceListener.onServiceDisconnected: BT state=" + bluetoothState); stopScoAudio(); bluetoothHeadset = null; bluetoothDevice = null; bluetoothState = State.HEADSET_UNAVAILABLE; updateAudioDeviceState(); Log.d(TAG, "onServiceDisconnected done: BT state=" + bluetoothState); }
Example 12
Source File: MainActivity.java From BlueToothEatPhone with Apache License 2.0 | 5 votes |
@Override public void onServiceConnected(int profile, BluetoothProfile proxy) { try { if (profile == BluetoothProfile.HEADSET) { // bh = (BluetoothHeadset) proxy; // if (bh.getConnectionState(mTouchObject.bluetoothDevice) != BluetoothProfile.STATE_CONNECTED){ // bh.getClass() // .getMethod("connect", BluetoothDevice.class) // .invoke(bh, mTouchObject.bluetoothDevice); // } } else if (profile == BluetoothProfile.A2DP) { /**使用A2DP的协议连接蓝牙设备(使用了反射技术调用连接的方法)*/ a2dp = (BluetoothA2dp) proxy; if (a2dp.getConnectionState(currentBluetoothDevice) != BluetoothProfile.STATE_CONNECTED) { a2dp.getClass() .getMethod("connect", BluetoothDevice.class) .invoke(a2dp, currentBluetoothDevice); Toast.makeText(MainActivity.this,"请播放音乐",Toast.LENGTH_SHORT).show(); getBondedDevices(); } } } catch (Exception e) { e.printStackTrace(); } }
Example 13
Source File: AppRTCBluetoothManager.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
@Override // Called to notify the client when the proxy object has been connected to the service. // Once we have the profile proxy object, we can use it to monitor the state of the // connection and perform other operations that are relevant to the headset profile. public void onServiceConnected(int profile, BluetoothProfile proxy) { if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { return; } Log.d(Config.LOGTAG, "BluetoothServiceListener.onServiceConnected: BT state=" + bluetoothState); // Android only supports one connected Bluetooth Headset at a time. bluetoothHeadset = (BluetoothHeadset) proxy; updateAudioDeviceState(); Log.d(Config.LOGTAG, "onServiceConnected done: BT state=" + bluetoothState); }
Example 14
Source File: AppRTCBluetoothManager.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
@Override /** Notifies the client when the proxy object has been disconnected from the service. */ public void onServiceDisconnected(int profile) { if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { return; } Log.d(Config.LOGTAG, "BluetoothServiceListener.onServiceDisconnected: BT state=" + bluetoothState); stopScoAudio(); bluetoothHeadset = null; bluetoothDevice = null; bluetoothState = State.HEADSET_UNAVAILABLE; updateAudioDeviceState(); Log.d(Config.LOGTAG, "onServiceDisconnected done: BT state=" + bluetoothState); }
Example 15
Source File: AppRTCBluetoothManager.java From Conversations with GNU General Public License v3.0 | 5 votes |
@Override // Called to notify the client when the proxy object has been connected to the service. // Once we have the profile proxy object, we can use it to monitor the state of the // connection and perform other operations that are relevant to the headset profile. public void onServiceConnected(int profile, BluetoothProfile proxy) { if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { return; } Log.d(Config.LOGTAG, "BluetoothServiceListener.onServiceConnected: BT state=" + bluetoothState); // Android only supports one connected Bluetooth Headset at a time. bluetoothHeadset = (BluetoothHeadset) proxy; updateAudioDeviceState(); Log.d(Config.LOGTAG, "onServiceConnected done: BT state=" + bluetoothState); }
Example 16
Source File: AppRTCBluetoothManager.java From Conversations with GNU General Public License v3.0 | 5 votes |
@Override /** Notifies the client when the proxy object has been disconnected from the service. */ public void onServiceDisconnected(int profile) { if (profile != BluetoothProfile.HEADSET || bluetoothState == State.UNINITIALIZED) { return; } Log.d(Config.LOGTAG, "BluetoothServiceListener.onServiceDisconnected: BT state=" + bluetoothState); stopScoAudio(); bluetoothHeadset = null; bluetoothDevice = null; bluetoothState = State.HEADSET_UNAVAILABLE; updateAudioDeviceState(); Log.d(Config.LOGTAG, "onServiceDisconnected done: BT state=" + bluetoothState); }