简体   繁体   English

在Android上连接蓝牙SPP

[英]Connection bluetooth SPP on android

Sorry friends to bother you. 对不起朋友打扰您了。 I am stay at home mom and new in Android development which I took us as part time job. 我待在家里,现在还是Android开发的新手,我把我们当做兼职。 I have expereince in Java development. 我有Java开发方面的经验。

I have tried to look that bluetooth chat example and searched here a lot about from where to start. 我试图看一下该蓝牙聊天示例,并在这里搜索了很多有关从何开始的信息。 The bluetooth chat sample never shows up the list of paired devices when I tried to run on my mobile. 当我尝试在手机上运行时,蓝牙聊天示例从不显示已配对设备的列表。 Whereas here in lot of questions there is thing UUID is used. 而在许多问题中,有使用UUID的东西。 I am not able to find out from where my friends retreived it. 我无法从朋友那里找到它。

My question is can someone guide me just few lines from where to start, I have a SPP device paired/unpaired (Idont know its UUID) I wish to connect it through my mobile. 我的问题是有人可以从头开始指导我几行,我有一个配对/未配对的SPP设备(我不知道它的UUID),我希望通过手机连接它。 Just few lines of assistance is requested as time of you people is very precious, I understand it is my stupid question. 由于你们的时间是非常宝贵的,因此只需要几行帮助,我知道这是我的愚蠢问题。

Thanks. 谢谢。

i use bluetooth spp in my app and get my data binary, so i can drop you some lines of code i use. 我在我的应用程序中使用了蓝牙spp并获取了我的数据二进制文件,因此我可以为您删除一些我使用的代码行。

private BluetoothSocket sock;
private InputStream in;
private BluetoothDevice zee;

    /*
     * ****PAIR DONGLE****
     */

    zee = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("YO:UR:MA:CA:DR:ES:S");

    m = zee.getClass().getMethod("createRfcommSocket",
            new Class[] { int.class });
    sock = (BluetoothSocket) m.invoke(zee, Integer.valueOf(1));
    sock.connect();
    int temp = 0;
    in = sock.getInputStream();

    try {
        while (true) {
            temp = in.read();
            //do what you like with your byte stored in temp
    } catch (IOException e) {}

hope that helps 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM