Java Code Examples for android.bluetooth.BluetoothProfile#ServiceListener

The following examples show how to use android.bluetooth.BluetoothProfile#ServiceListener . 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 vote down vote up
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: AppRTCBluetoothManager.java    From imsdk-android with MIT License 4 votes vote down vote up
protected boolean getBluetoothProfileProxy(
    Context context, BluetoothProfile.ServiceListener listener, int profile) {
  return bluetoothAdapter.getProfileProxy(context, listener, profile);
}
 
Example 3
Source File: AppRTCBluetoothManager.java    From flutter-incall-manager with ISC License 4 votes vote down vote up
protected boolean getBluetoothProfileProxy(
    Context context, BluetoothProfile.ServiceListener listener, int profile) {
  return bluetoothAdapter.getProfileProxy(context, listener, profile);
}
 
Example 4
Source File: AppRTCBluetoothManager.java    From react-native-incall-manager with ISC License 4 votes vote down vote up
protected boolean getBluetoothProfileProxy(
    Context context, BluetoothProfile.ServiceListener listener, int profile) {
  return bluetoothAdapter.getProfileProxy(context, listener, profile);
}
 
Example 5
Source File: AppRTCBluetoothManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
protected boolean getBluetoothProfileProxy(
        Context context, BluetoothProfile.ServiceListener listener, int profile) {
    return bluetoothAdapter.getProfileProxy(context, listener, profile);
}
 
Example 6
Source File: AppRTCBluetoothManager.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
protected boolean getBluetoothProfileProxy(
        Context context, BluetoothProfile.ServiceListener listener, int profile) {
    return bluetoothAdapter.getProfileProxy(context, listener, profile);
}