android设置蓝牙扫描时间,如何在android中更改蓝牙适配器的扫描模式?

您无法使用第三方(非内核/非系统)应用程序在4.2及更高版本中设置Android设备的扫描模式。您只能启用发现(SCAN_MODE_CONNECTABLE_DISCOVERABLE),并选择使用EXTRA_DISCOVERABLE_DURATION来设置特定的持续时间。您可以通过设置duration parameter to 1来有效取消发现。

证据,采取一目了然通过Android Source,重点BluetoothAdapter.java:

/**

* Set the Bluetooth scan mode of the local Bluetooth adapter.

*

The Bluetooth scan mode determines if the local adapter is

* connectable and/or discoverable from remote Bluetooth devices.

*

For privacy reasons, discoverable mode is automatically turned off

* after duration seconds. For example, 120 seconds should be

* enough for a remote device to initiate and complete its discovery

* process.

*

Valid scan mode values are:

* {@link #SCAN_MODE_NONE},

* {@link #SCAN_MODE_CONNECTABLE},

* {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}.

*

If Bluetooth state is not {@link #STATE_ON}, this API

* will return false. After turning on Bluetooth,

* wait for {@link #ACTION_STATE_CHANGED} with {@link #STATE_ON}

* to get the updated value.

*

Requires {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}

*

Applications cannot set the scan mode. They should use

* startActivityForResult(

* BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE})

* instead.

*

* @param mode valid scan mode

* @param duration time in seconds to apply scan mode, only used for

* {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}

* @return true if the scan mode was set, false otherwise

* @hide

*/

public boolean setScanMode(int mode, int duration) {

if (getState() != STATE_ON) return false;

try {

synchronized(mManagerCallback) {

if (mService != null) return mService.setScanMode(mode, duration);

}

} catch (RemoteException e) {Log.e(TAG, "", e);}

return false;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值