android - 单击按钮即可发现蓝牙,无需导航至蓝牙设置页面

标签 android button bluetooth

我们如何在不进入蓝牙设置页面的情况下点击按钮就可以发现蓝牙。

 bt_strength.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            if (mBtAdapter.getScanMode()!= BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) 
           {

          make discoverable

            }

我该怎么做?

非常感谢任何帮助,谢谢

最佳答案

您将从以下位置获得蓝牙适配器对象:

 BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

点击按钮你可以调用:

  mBluetoothAdapter.startDiscovery();

这将使您的蓝牙进入发现模式

关于android - 单击按钮即可发现蓝牙,无需导航至蓝牙设置页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11045149/

相关文章:

android - 如何启用按钮取决于 API 7 中的编辑文本

ios - 在文本字段中键入时不会禁用 UIKeyCommand (Swift)

java - Android蓝牙发现未找到设备

linux - 以非 root 用户身份访问 Bluez 库

android - 设置framelayout边距及其子元素的宽度、高度和位置

java - 媒体应用程序缓冲时间太长

java - 无法将 ArrayList 从 AsyncTask 传递到 Activity (Android)

java - "Unfortunately MyApp has stopped"当我按下一个按钮

javascript - 从 JavaScript 创建的按钮执行函数的正确方法?

asp.net - 防止双击asp.net按钮