问题描述
有已经在这里这样类似的问题,但答案和建议,涉及到旧版本的Android。据我所知,蓝牙堆栈已完全从4.2开始修订和较旧的解决方案不工作了。
There are similar questions to this here already, but the answers and suggestions relate to older versions of Android. I understand that the bluetooth stack has been completely revised from 4.2 onwards and older solutions do not work anymore.
我已经尝试了所有没有用旧的解决方案。使用专用的API不再工作,因为他们已经改变。我不介意使用私有API,但它必须与最新版本及更高版本(即API 17 +)
I have tried all the older solutions to no avail. the use of the private APIs no longer works because they have changed. I dont mind using private APIs but it must work on the newest versions and later (ie API 17+)
我试图做到以下几点:
建立一个Android设备,并使用传统的PIN配对的嵌入式设备之间的蓝牙配对没有嵌入式设备被发现,也没有用户不必手动输入PIN码。其实我想没有PIN码输入对话框,在所有。
set up a bluetooth pairing between an Android device and an embedded device using legacy PIN pairing without the embedded device being discoverable nor the user having to manually enter the PIN. In fact I want no PIN entry dialog box at all.
该计划是这两个设备具有predefined共享秘密的PIN码,这样我可以编程方式执行配对,然后打开它们之间的连接RFCOMM。所有这一切都没有UI。嵌入式设备的硬件地址是已知的Android程序
The plan is that the two devices have a predefined shared secret PIN, so that I can perform the pairing programmatically and then open an RFCOMM connection between them. All of this without UI. The hardware address of the embedded device is known to the Android program.
这里没有安全问题。该项目涉及只谈一个nearyby,通过BT小型嵌入式设备越简单越好。
There is no security issue here. the project involves just talking to a nearyby, small embedded device through BT as simple as possible.
这可能会在Android 4.2的工作思路(果冻豆)最欢迎的,谢谢。
Ideas that might work on Android 4.2 (Jelly Bean) most welcome, thanks.
推荐答案
原来有些问题是嵌入式设备中。在Android方面,以下工作:
turns out some of the problem was inside the embedded device. on the Android side, the following works:
的BluetoothSocket S = NULL;
BluetoothSocket s = null;
try
{
s = device.createInsecureRfcommSocketToServiceRecord(SerialPortServiceClass_UUID);
}
catch (IOException e)
{
Log.e(TAG, "BT connect failed", e);
return false;
}
其中,
private static final UUID SerialPortServiceClass_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
这篇关于Android的蓝牙PIN码配对不会对Android用户界面4.2+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!