Android如何实现蓝牙自动配对
Android开发如何实现蓝牙的自动配对,能够写代码实现设置pin码和配对的功能,不要弹出系统自带的对话框。
急求答案!!
[解决办法]
eoe 看到过:
<receiver android:name=".broadcast.PairingRequest">
<intent-filter>
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
<action android:name="android.bluetooth.device.action.PAIRING_CANCEL" />
</intent-filter>
</receiver>
public class PairingRequest extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent){
if (intent.getAction().equals("ACTION_PAIRING_REQUEST")) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
byte[] pinBytes = BluetoothDevice.convertPinToBytes("1234");
device.setPin(pinBytes);
}
}
}