小编use*_*095的帖子

Android配对蓝牙设备没有针脚对话

我想配对我的Android手机和SPP蓝牙没有针脚和确认对话.我有这个代码,注册BroadcastReceiver:

IntentFilter filter = new IntentFilter(ACTION_PAIRING_REQUEST);
                registerReceiver(mPairReceiver, filter); 
                pairDevice(device);
Run Code Online (Sandbox Code Playgroud)

pairDevice方法:

 private void pairDevice(BluetoothDevice device) {
    try {

        Method method = device.getClass().getMethod("createBond", (Class[]) null);
        method.invoke(device, (Object[]) null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

BroadcastReceiver:

private final BroadcastReceiver mPairReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (ACTION_PAIRING_REQUEST.equals(action)) {    
            System.out.println("ACTION_PAIRING_REQUEST");
            setBluetoothPairingPin(device);
        } 
    }
};
Run Code Online (Sandbox Code Playgroud)

setBluetoothPairingPin方法:

public void setBluetoothPairingPin(BluetoothDevice device)
{
    byte[] pinBytes = convertPinToBytes("0000");
    try {
        Log.d(TAG, …
Run Code Online (Sandbox Code Playgroud)

android bluetooth

7
推荐指数
0
解决办法
2529
查看次数

标签 统计

android ×1

bluetooth ×1