When you connect a Bluetooth device that is known to be paired with a password, you can complete the pairing in the code, but the pairing window is still ejected from the system.
This is undoubtedly unpleasant.
So, try to block out the pairing window.
Points:
- Bluetooth pairing broadcast from interrupt system
- Need to use the clsutils Open source Framework
- Personal test successfully intercepted on Android 4.4, not on 4.2, maybe a high version of Bluetooth pairing broadcast set to order broadcast?
Code
Public classBluetoothconnectreceiverextendsbroadcastreceiver{Private FinalString TAG = "Bluetoothconnectreceiver"; @SuppressLint ("Newapi") @Override Public voidOnReceive (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 (); } } }}
Direct silent pairing with a preset password.
Manifest
<receiver android:name= ". Bluetoothconnectreceiver "> <intent-filter android:priority=" "> <action android:name=" Android.bluetooth.device.action.PAIRING_REQUEST "/> </intent-filter></receiver>
The receiver's priority is set to a maximum of 1000, guaranteeing the first broadcast notification.
Android screen bluetooth connection when the first pairing system pop-up window