嘿大家!
在Android之前开始使用蓝牙编程.但现在我遇到了一些问题.我想知道为什么配对请求有时会出现在通知栏中,有时会跳过此对话框并直接显示对话框.
例如:我从嵌入式设备发起配对请求,然后会出现如下通知:

有时我不必费心去通知,我的对话框就像我预期的那样显示出来.

有没有办法捕获该通知并显示对话框,或者当我启动蓝牙配对时,这是我的代码中的错误?
编辑:
更新1:
检查了Reno给我的答案,这实际上取决于各种各样的事情.还有其他方法可以直接显示对话框.当配对请求到达时,调用以下方法.进行检查以查看对话框是应该显示在前台(true)还是显示为通知(false):
public boolean shouldShowDialogInForeground(String deviceAddress) {
// If Bluetooth Settings is visible
if (mForegroundActivity != null) return true;
long currentTimeMillis = System.currentTimeMillis();
SharedPreferences sharedPreferences = getSharedPreferences();
// If the device was in discoverABLE mode recently
long lastDiscoverableEndTime = sharedPreferences.getLong(
BluetoothDiscoverableEnabler.SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP, 0);
if ((lastDiscoverableEndTime + GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND)
> currentTimeMillis) {
return true;
}
// If the device was discoverING recently
if (mAdapter != null && mAdapter.isDiscovering()) {
return true;
} else if ((sharedPreferences.getLong(SHARED_PREFERENCES_KEY_DISCOVERING_TIMESTAMP, 0) + …Run Code Online (Sandbox Code Playgroud)