Update code for public Bluetooth APIs

Change-Id: Iab22e4ae3206f9085b2d53b8b18dc2abd6197226
This commit is contained in:
Jaikumar Ganesh
2010-08-18 21:33:33 -07:00
parent 097981df93
commit 5809d33296
5 changed files with 119 additions and 109 deletions

View File

@@ -23,6 +23,7 @@ import android.app.AlertDialog;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Config;
@@ -117,11 +118,21 @@ public class LocalBluetoothManager {
mEventRedirector = new BluetoothEventRedirector(this);
mEventRedirector.start();
mBluetoothA2dp = new BluetoothA2dp(context);
mAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.A2DP);
return true;
}
private BluetoothProfile.ServiceListener mProfileListener =
new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
mBluetoothA2dp = (BluetoothA2dp) proxy;
}
public void onServiceDisconnected(int profile) {
mBluetoothA2dp = null;
}
};
public BluetoothAdapter getBluetoothAdapter() {
return mAdapter;
}
@@ -184,12 +195,11 @@ public class LocalBluetoothManager {
}
// If we are playing music, don't scan unless forced.
Set<BluetoothDevice> sinks = mBluetoothA2dp.getConnectedSinks();
if (sinks != null) {
for (BluetoothDevice sink : sinks) {
if (mBluetoothA2dp.getSinkState(sink) == BluetoothA2dp.STATE_PLAYING) {
return;
}
if (mBluetoothA2dp != null) {
Set<BluetoothDevice> sinks = mBluetoothA2dp.getConnectedDevices();
if (sinks.size() > 0) {
BluetoothDevice sink = sinks.toArray(new BluetoothDevice[sinks.size()])[0];
if (mBluetoothA2dp.isA2dpPlaying(sink)) return;
}
}
}