如何强制蓝牙配对请求提示实际上出现而不是发送到通知托盘?

问题描述

我正在开发的应用程序已连接到其他蓝牙设备,它应要求用户输入PIN,以便该设备与手机绑定。可以使用此功能,但是无论如何我都会遇到问题,总是将提示输入PIN的提示(因此会弹出一个小窗口)发送到通知托盘。这意味着我的用户将必须a)注意到配对请求/ PIN提示是首先发送到那里的,并且b)他们将必须手动打开通知托盘,点击通知以使提示出现,然后进行选择。

这仅在Kindle 8th gen,API 25+中发生。我有一个Samsung标签,API 19和一个Kindle 6th Gen,API 22,它们都可以正常工作。

有人知道如何确保始终将提示显示在最前面吗?这是我尝试过的!

Is there a way to ensure Bluetooth pairing pin input dialogue will pop up instead of being hidden as a notification?

Bring bluetooth pairing dialogue to the front

Bluetooth pairing request on notification bar?

Bring Bluetooth pairing request notification dialog on front to ask for PIN

//Immediately before connecting
startdiscovery();
stopdiscovery();
//Same but without stopping discovery
startdiscovery();
<insert connection method>
//Tried this to ensure it actually discoveres mode
if(!irisBluetooth.localBTAdapter.isdiscovering())
    {
        irisBluetooth.localBTAdapter.startdiscovery();
    }
    while(irisBluetooth.localBTAdapter.isdiscovering()){
        irisBluetooth.localBTAdapter.canceldiscovery();
    }
//Call this and pass target device combined with/without prevIoUs attempts
public static void pairDevice(BluetoothDevice device) {
    try {
        Method method = device.getClass().getmethod("createBond",(Class[]) null);
        method.invoke(device,(Object[]) null);
        //From API 19.
        //  device.createBond();
    } catch (Exception e) {
        e.printstacktrace();
    }
}
//Call this method for bonding
try {
    device.createBond();
}
catch (Exception e){
    Log.e("TAG",e.getMessage());
}
//Call this combined with/without prevIoUs attempts
private void startBluetoothPairing(BluetoothDevice device) {
    Intent pairingIntent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST);
    pairingIntent.putExtra(BluetoothDevice.EXTRA_DEVICE,device);
    pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,BluetoothDevice.PAIRING_VARIANT_PIN);
    //pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY,1234);
    //device.setPin(new byte[]{1,2,3,4});  <- DOES NOT CHANGE ANYTHING
    pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    irisBluetooth.getMain().startActivityForResult(pairingIntent,5);
}

所有这些方法都可以达到配对的最终目的。唯一的问题是配对请求/ PIN提示会发送到通知托盘!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)