【问题标题】:Disable Bluetooth onClick android禁用蓝牙 onClick android
【发布时间】:2014-05-07 19:06:11
【问题描述】:

如何在点击按钮时禁用蓝牙?

public void btd(View view) { 
    BluetoothAdapter blue = BluetoothAdapter.getDefaultAdapter();

        blue.disable();
}

或

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
         if (mBluetoothAdapter == null) {
             // Device does not support Bluetooth

             }else{

             if (!mBluetoothAdapter.isEnabled()) {

                mBluetoothAdapter.enable();

             }else{

              mBluetoothAdapter.disable();    

             }

             }


<uses-permission android:name="android.permission.BLUETOOTH" />  
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> 

该代码仅在我启用蓝牙 vis 代码时才有效,但如果通过通知栏启用,则应用程序将被强制关闭!!

这里是错误日志http://justpaste.it/fd7t

【问题讨论】:

标签: android bluetooth onclick


【解决方案1】:

简单

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    • 2018-04-27
    • 2013-10-25
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多