【问题标题】:How to enable/disable bluetooth in a service class in android? [duplicate]如何在android的服务类中启用/禁用蓝牙? [复制]
【发布时间】:2013-05-21 23:34:25
【问题描述】:

我想从我的安卓服务类中启用禁用蓝牙,我正在使用以下代码

     BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();    
                    if (!mBluetoothAdapter.isEnabled()) {
                        mBluetoothAdapter.enable();
                    }else{ 
                        mBluetoothAdapter.disable(); 
                    }  

但它不起作用,所以我如何从我的服务类启用/禁用蓝牙以及我需要哪些权限

【问题讨论】:

  • 检查但没有解决我的问题
  • 您是否遇到任何错误?尝试使用调试器或Log 消息来查看控制流。你可能会注意到它的原因。
  • 没有错误只是不工作......

标签: android service permissions bluetooth


【解决方案1】:

使用蓝牙权限:

您是否在清单文件中使用了此权限:
使用权限 android:name="android.permission.BLUETOOTH"

【讨论】:

  • 是的,我在菜单中有蓝牙和蓝牙管理员权限
猜你喜欢
  • 1970-01-01
  • 2019-06-21
  • 1970-01-01
  • 2011-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-27
  • 2016-09-12
相关资源
最近更新 更多