【问题标题】:getDefaultAdapter() method is not supported when i am using this code使用此代码时不支持 getDefaultAdapter() 方法
【发布时间】:2022-01-02 08:51:18
【问题描述】:

当我使用此代码时,getDefaultAdapter 不支持,showing toast 也错误。

【问题讨论】:

    标签: android kotlin bluetooth android-emulator


    【解决方案1】:

    您可以参考this answer。 您可以尝试类似

    BluetoothAdapter.getDefaultAdapter()
    

    【讨论】:

      【解决方案2】:

      getDefaultAdapter() 可以,但他们建议您迁移到使用 BluetoothManager 和 getAdapter()

      在活动中:

      val bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
      m_bluetoothAdapter = bluetoothManager.adapter
      

      在片段中:

      val bluetoothManager = requireContext().getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
      m_bluetoothAdapter = bluetoothManager.adapter
      

      没有toast() 函数。它显然是由core-ktx Jetpack 库提供的,后来被删除了。使用显示 Toasts 的standard way

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-04-23
        • 2020-04-13
        • 2020-12-06
        • 2019-12-17
        • 1970-01-01
        • 1970-01-01
        • 2020-09-04
        相关资源
        最近更新 更多