我想连接一个蓝牙耳机到我的android设备使用android开发者页面作为参考。 http://developer.android.com/guide/topics/connectivity/bluetooth.htmlandroid蓝牙耳机getprofileproxy返回null
我的问题是,当我试图调用getProfileProxy(context,mProfileListener,BluetoothProfile.HEADSET)方法时,我不确定要传递的上下文是什么?我从这里的问题找到这个错误: can not connect to bluetooth headset in android
我对此非常新,所以我会提前道歉,如果这是一个愚蠢的问题。我花了很多时间去研究这个问题,但是我发现每个例子和文档都只有一个上下文变量,所以我不知道我错在哪里。我的代码,或多或少是来自android文档的副本:
//建立到代理的连接。 boolean mProfileProxy = mBluetoothAdapter.getProfileProxy(context,mProfileListener,BluetoothProfile.HEADSET); Log.d(TAGP,“Get Adapter Success:”+ mProfileProxy); Log.d(TAGP,“Get Adapter Success:”+ mProfileProxy); Log.d(TAGP,“Context:”+ context);
BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
if (profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset = (BluetoothHeadset) proxy;
Log.d(TAGP,"BLuetooth Headset: "+mBluetoothHeadset);
Log.d(TAGP,"Proxy: "+proxy);
}
}
public void onServiceDisconnected(int profile) {
if (profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset = null;
}
}
};
感谢您的帮助! – Graham 2013-03-24 17:58:14