如何禁用蓝牙机器人? [英] How to disable the Bluetooth in android?
本文介绍了如何禁用蓝牙机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/3806536/how-to-enable-disable-bluetooth-programmatically-in-android\">How启用/ android中编程方式禁用蓝牙
块引用>我在Android开发的新手。我不能在我的应用程序禁用蓝牙。在这里,我已经使用了checkbox.Enabling其中实现蓝牙,但同时禁用它仍然使..我该怎么办?
我的code:
enable_chkbox =(复选框)findViewById(R.id.chkboxenable);
enable_chkbox.setOnCheckedChangeListener(新OnCheckedChangeListener(){ @覆盖
公共无效onCheckedChanged(CompoundButton buttonView,布尔器isChecked){
// TODO自动生成方法存根
如果(buttonView.isChecked())
{
如果(!mBluetoothAdapter.isEnabled()){
意图enableBtIntent =新意图(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent,REQUEST_ENABLE_BT);
}
否则如果(!buttonView.isChecked())//更新
{
mBluetoothAdapter.disable();
//完();
}
}
}
});Android清单文件权限:
&LT;使用许可权的android:NAME =android.permission.BLUETOOTH/&GT;
&LT;使用许可权的android:NAME =android.permission.BLUETOOTH_ADMIN/&GT;
解决方案如果 code是没有用的,你的
别的。
试试这个。BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
如果(buttonView.isChecked())
{
如果(!mBluetoothAdapter.isEnabled()){
意图enableBtIntent =新意图(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent,REQUEST_ENABLE_BT);
}
}
其他
{
mBluetoothAdapter.disable();
//完();
}Possible Duplicate:
How to enable/disable bluetooth programmatically in androidI'm a newbie in android development. I'm not able to disable Bluetooth in my app. Here I've used a checkbox.Enabling of which enables the bluetooth but while disabling it remains enable.. What do I do?
My code:
enable_chkbox=(CheckBox)findViewById(R.id.chkboxenable); enable_chkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(buttonView.isChecked()) { if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } else if(!buttonView.isChecked())//updated { mBluetoothAdapter.disable(); //finish(); } } } });
Android Manifest file permissions:
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
解决方案Your
else if
code is of no use. Try this.BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if(buttonView.isChecked()) { if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } } else { mBluetoothAdapter.disable(); //finish(); }
这篇关于如何禁用蓝牙机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文