【问题标题】:How to programmatically enable or disable Bluetooth Profiles in Android?如何以编程方式在 Android 中启用或禁用蓝牙配置文件?
【发布时间】:2017-05-09 10:13:10
【问题描述】:

我有一个通过蓝牙连接到手机的配对设备列表。在某些时候,我必须禁用/启用将媒体或联系人详细信息共享到我的配对设备。 我的要求是在 android 中以编程方式执行此操作。 我已经搜索过这个,但我找不到任何解决方案。

如果可以,请告诉我?

【问题讨论】:

  • 您找到解决方案了吗?

标签: android bluetooth a2dp


【解决方案1】:

只需尝试启用或禁用蓝牙。

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();    

            if (mBluetoothAdapter.isEnabled()) {
                mBluetoothAdapter.disable(); 
            }else {
                mBluetoothAdapter.enable(); 
            }

【讨论】:

  • 但我无法完全禁用蓝牙。
  • 在我的例子中是 mBluetoothAdapter.disable();可以很好地禁用蓝牙。你能展示你的代码吗?
  • 您添加了权限吗?
  • 使用您提供的代码,可以禁用蓝牙。但这不是我的要求。我必须禁用蓝牙配置文件而不禁用蓝牙。希望你现在得到我。
【解决方案2】:

试试

获取默认蓝牙适配器

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();    

启用

 bluetoothAdapter.enable(); 

禁用

bluetoothAdapter.disable(); 

检查状态

bluetoothAdapter.isEnabled();

【讨论】:

  • 感谢您提供的代码。但这不是我的要求。我必须在不禁用蓝牙的情况下禁用蓝牙配置文件,例如媒体、联系方式。
  • 没有。我只想禁用蓝牙配置文件。蓝牙连接和配对设备都需要在那里。
猜你喜欢
  • 2011-04-17
  • 1970-01-01
  • 1970-01-01
  • 2011-03-14
  • 2011-06-22
  • 1970-01-01
  • 1970-01-01
  • 2011-09-22
  • 1970-01-01
相关资源
最近更新 更多