gpt4 book ai didi

android 蓝牙耳机 getprofileproxy 返回 null

转载 作者:行者123 更新时间:2023-11-29 01:55:27 24 4
gpt4 key购买 nike

我正在尝试使用 android 开发人员页面作为引用将蓝牙耳机连接到我的 android 设备。 http://developer.android.com/guide/topics/connectivity/bluetooth.html

我的问题是当我尝试调用 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,"获取适配器成功:"+mProfileProxy); Log.d(TAGP,"上下文:"+上下文);

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;
}
}
};

最佳答案

上下文可以是 Activity 服务上下文。因此,如果上面的代码位于扩展ActivityService 的类中,您可以传递this
您可以在 Using the Android RecognizerIntent with a bluetooth headset 使用我的回答

关于android 蓝牙耳机 getprofileproxy 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15464425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com