连接配对密码已知且固定的蓝牙设备时,明明在代码里就可以完成配对,却依旧被系统弹出配对窗口.这无疑是令人难受的.所以,便尝试着去屏蔽掉这个配对窗口. 要点:中断系统发出的蓝牙配对广播需要用到ClsUtils开源框架个人测试在Android 4.4上成功拦截,在4.2上不行,也许 ...
连接配对密码已知且固定的蓝牙设备时,明明在代码里就可以完成配对,却依旧被系统弹出配对窗口.
这无疑是令人难受的.
所以,便尝试着去屏蔽掉这个配对窗口.
要点:
- 中断系统发出的蓝牙配对广播
- 需要用到ClsUtils开源框架
- 个人测试在Android 4.4上成功拦截,在4.2上不行,也许是高版本把蓝牙配对广播设为了有序广播?
code:
public class BluetoothConnectReceiver extends BroadcastReceiver{ private final String TAG = "BluetoothConnectReceiver"; @SuppressLint("NewApi") @Override public void onReceive(Context context, Intent intent) { Log.i(TAG, TAG + " -> BluetoothConnectReceiver start!"); if (intent.getAction().equals("android.bluetooth.device.action.PAIRING_REQUEST")) { BluetoothDevice btDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); Log.i(TAG, TAG + " -> ddd"); try { Log.i(TAG, TAG + " -> Device Name = " + btDevice.getName()); if ("Device Name X".equals(btDevice.getName())) { abortBroadcast(); ClsUtils.setPin(btDevice.getClass(), btDevice, "password"); ClsUtils.createBond(btDevice.getClass(), btDevice); ClsUtils.cancelPairingUserInput(btDevice.getClass(), btDevice); } } catch (Exception e) { e.printStackTrace(); } } }}
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:Android 屏蔽蓝牙连接时的首次配对系统弹窗
关键词:Android
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。