在 Android 上禁用蓝牙可发现模式 [英] Disable Bluetooth discoverable mode on Android

查看:42
本文介绍了在 Android 上禁用蓝牙可发现模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android 文档中找到了如何打开蓝牙可发现模式:

I found in the Android documentation how to turn Bluetooth discoverability mode on:

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);

这将使设备在 300 秒内可被发现(文档).

This will make the device discoverable for 300 seconds (documentation).

我的问题是:如何在超时发生之前关闭可发现性?我想复制设置|无线和网络|蓝牙设置小程序中的相应设置,以便通过单击打开和关闭可发现性.

My question is: how to turn discoverability OFF before this timeout occurs? I'd like to replicate the corresponding setting in Settings|Wireless and networks|Bluetooth settings applet, that allows discoverability to be turned on and off with a click.

有什么帮助吗?

推荐答案

只需发送一个持续时间为 1(或 0 甚至可能有效)的新的可发现请求:

Just send a new discoverable request with duration 1 (or 0 might even work):

Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 1);
startActivity(discoverableIntent);

这篇关于在 Android 上禁用蓝牙可发现模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆