Started bluetooth headset vendor events support
This commit is contained in:
parent
674f3b4a02
commit
9a0ad7cd86
2 changed files with 43 additions and 1 deletions
35
src/org/linphone/BluetoothActionReceiver.java
Normal file
35
src/org/linphone/BluetoothActionReceiver.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package org.linphone;
|
||||||
|
|
||||||
|
import org.linphone.mediastream.Log;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothHeadset;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
|
public class BluetoothActionReceiver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (intent.getAction().equals(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)) {
|
||||||
|
BluetoothDevice device = (BluetoothDevice) intent.getExtras().get(BluetoothDevice.EXTRA_DEVICE);
|
||||||
|
String command = intent.getExtras().getString(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD);
|
||||||
|
int type = intent.getExtras().getInt(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE);
|
||||||
|
|
||||||
|
Object[] temp = (Object[]) intent.getExtras().get(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS);
|
||||||
|
String[] args = new String[temp.length];
|
||||||
|
String logArgs = "";
|
||||||
|
for (int i = 0; i < temp.length; i++) {
|
||||||
|
args[i] = (String) temp[i];
|
||||||
|
logArgs += args[i] + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d("Bluetooth headset event from " + device.getName() + ", command: " + command + " (type: " + type + ") with args: " + logArgs);
|
||||||
|
|
||||||
|
//TODO: parse command/args and do something with it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -150,6 +150,7 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
private BluetoothHeadset mBluetoothHeadset;
|
private BluetoothHeadset mBluetoothHeadset;
|
||||||
private BluetoothProfile.ServiceListener mProfileListener;
|
private BluetoothProfile.ServiceListener mProfileListener;
|
||||||
private BroadcastReceiver bluetoothReiceiver = new BluetoothManager();
|
private BroadcastReceiver bluetoothReiceiver = new BluetoothManager();
|
||||||
|
private BroadcastReceiver bluetoothActionReceiver = new BluetoothActionReceiver();
|
||||||
public boolean isBluetoothScoConnected;
|
public boolean isBluetoothScoConnected;
|
||||||
public boolean isUsingBluetoothAudioRoute;
|
public boolean isUsingBluetoothAudioRoute;
|
||||||
private boolean mBluetoothStarted;
|
private boolean mBluetoothStarted;
|
||||||
|
@ -252,14 +253,16 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
if (profile == BluetoothProfile.HEADSET) {
|
if (profile == BluetoothProfile.HEADSET) {
|
||||||
|
Log.d("Bluetooth headset connected");
|
||||||
|
mServiceContext.registerReceiver(bluetoothActionReceiver, new IntentFilter(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT));
|
||||||
mBluetoothHeadset = (BluetoothHeadset) proxy;
|
mBluetoothHeadset = (BluetoothHeadset) proxy;
|
||||||
isBluetoothScoConnected = true;
|
isBluetoothScoConnected = true;
|
||||||
Log.d("Bluetooth headset connected");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
public void onServiceDisconnected(int profile) {
|
public void onServiceDisconnected(int profile) {
|
||||||
if (profile == BluetoothProfile.HEADSET) {
|
if (profile == BluetoothProfile.HEADSET) {
|
||||||
|
mServiceContext.unregisterReceiver(bluetoothActionReceiver);
|
||||||
mBluetoothHeadset = null;
|
mBluetoothHeadset = null;
|
||||||
isBluetoothScoConnected = false;
|
isBluetoothScoConnected = false;
|
||||||
Log.d("Bluetooth headset disconnected");
|
Log.d("Bluetooth headset disconnected");
|
||||||
|
@ -748,6 +751,10 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
mServiceContext.unregisterReceiver(bluetoothReiceiver);
|
mServiceContext.unregisterReceiver(bluetoothReiceiver);
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mServiceContext.unregisterReceiver(bluetoothActionReceiver);
|
||||||
|
} catch (Exception e) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30))
|
if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30))
|
||||||
mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
|
mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
|
||||||
|
|
Loading…
Reference in a new issue