0

我如何理解蓝牙 API 有两个 Java 类,用于在应用程序中包含 HFP 配置文件: BluetoothHeadset , BluetoothHeadsetClient 。但是在我的 Andoid 工作室中,我没有 BluetoothHeadsetClient,只有 BluetoothHeadset。我如何拨打号码或处理来电或从 Android 应用程序创建拨出电话?

如果我写


    val Bluetooth_Profile_HEADSET_CLIENT =
        BluetoothProfile::class.java.getField("HEADSET_CLIENT")[null] as Int

    val mProfileListener: ServiceListener = object : ServiceListener {
        override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
            if (profile == Bluetooth_Profile_HEADSET_CLIENT) {
                Log.d("[Bluetooth]","Headset client connected")
                //proxy is BluetoothHeadsetClient
            }
        }
        override fun onServiceDisconnected(profile: Int) {
            Log.d("[Bluetooth]","Headset client disconnected")
        }
    }

mBluetoothAdapter!!.getProfileProxy(this, mProfileListener, Bluetooth_Profile_HEADSET_CLIENT);

我得到那个错误:

/BluetoothHeadsetClient: Could not bind to Bluetooth Headset Client Service with Intent { act=android.bluetooth.IBluetoothHeadsetClient }

此致

4

0 回答 0