连接或断开蓝牙键盘时,手机会重新搜索蓝牙设备

点击Forget的逻辑如下:

public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
System.out.println("ran.zhou-DPS-L139-Click OK Button");
EditText deviceName = (EditText) mRootView.findViewById(R.id.name);
mCachedDevice.setName(deviceName.getText().toString());
break;
case DialogInterface.BUTTON_NEGATIVE:
System.out.println("ran.zhou-DPS-L144-Click Forget Button");
mCachedDevice.unpair();
com.android.settings.bluetooth.Utils.updateSearchIndex(getContext(),
BluetoothSettings.class.getName(), mCachedDevice.getName(),
getString(R.string.bluetooth_settings),
R.drawable.ic_settings_bluetooth, false);
break;
}
}


 

蓝牙扫描逻辑如下:

private void startScanning() {
System.out.println("ran.zhou-BS-L290-startScanning");
if (isUiRestricted()) {
return;
}

if (!mAvailableDevicesCategoryIsPresent) {
getPreferenceScreen().addPreference(mAvailableDevicesCategory);
mAvailableDevicesCategoryIsPresent = true;
}

if (mAvailableDevicesCategory != null) {
setDeviceListGroup(mAvailableDevicesCategory);
removeAllDevices();
}

mLocalManager.getCachedDeviceManager().clearNonBondedDevices();
mAvailableDevicesCategory.removeAll();
mInitialScanStarted = true;
mLocalAdapter.startScanning(true);
}


  mtk6797/packages/apps/Settings / src/com/android/settings/bluetooth/BluetoothSettings.java

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mInitialScanStarted = false;
        mInitiateDiscoverable = true;

        mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
        getListView().setEmptyView(mEmptyView);
        mEmptyView.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);

        final SettingsActivity activity = (SettingsActivity) getActivity();
        mSwitchBar = activity.getSwitchBar();

        mBluetoothEnabler = new BluetoothEnabler(activity, mSwitchBar);
        mBluetoothEnabler.setupSwitchBar();
    }

以上方法中的mInitialScanStarted属性设置有问题,此处写死了为false,所以导致在后面引用的时候有一个判断,重新走进了扫描的流程。


解决方案:

mInitialScanStarted = false; 改为mInitialScanStarted = (savedInstanceState != null);


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
win10蓝牙总是自动断开连接的问题可能是由以下几个原因引起的。 首先,检查设备的电量情况。如果蓝牙设备电量不足,它可能会自动断开并尝试重新连接。确保蓝牙设备充满电或更换新电池,以解决此问题。 其次,确保蓝牙设备电脑之间的距离不超过合理范围。如果距离过远,蓝牙信号可能变弱,导致连接不稳定。尽量将蓝牙设备靠近计算机,以提高连接质量。 第三,更新蓝牙驱动程序。过的或损坏的蓝牙驱动程序可能会导致连接不稳定。打开设备管理器,找到蓝牙适配器并右键点击,选择“更新驱动程序”以自动下载并安装最新的驱动程序。 第四,检查蓝牙设备是否与其他设备发生冲突。某些设备可能会干扰蓝牙连接,例如无线键盘、鼠标或其他蓝牙设备。将其他蓝牙设备关闭或将其与电脑的距离保持一定距离,可以排除干扰问题。 最后,重置蓝牙适配器。打开设备管理器,找到蓝牙适配器并右键点击,选择“禁用设备”,然后再次右键点击选择“启用设备”来重置蓝牙适配器。这有可以解决连接问题。 如果以上方法仍然无法解决问题,建议尝试在其他设备连接蓝牙设备,以确定是蓝牙设备本身的问题还是与计算机设置有关的问题。如无法解决,请咨询专业技术人员或联系相关厂商的技术支持部门获取进一步的帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值