Android的RFCOMM与OBEX推不工作 [英] Android RFComm with OBEX Push not working

查看:144
本文介绍了Android的RFCOMM与OBEX推不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重拍一个Java应用程序转换成一个Android应用程序,但我不能使它发挥作用。该应用程序是为了聊到使用OBEX推技术。该设备可以不承担任何传入连接,它没有用户界面,但有些LED灯。

I am trying to remake a java application into an android application, but I cannot make it work. The application is meant to talk to a device that uses OBEX Push. The device cannot take any incoming connections and it has no user interface but some LEDs.

在Java code段我想重拍是以下内容:

The java code snippet I am trying to remake is following:

LocalDevice local;
local = LocalDevice.getLocalDevice();
local.setDiscoverable(DiscoveryAgent.LIAC);
String sConnectionURL = "btspp://localhost:" + myUUID + ";name=" + obexName;
this.server = (StreamConnectionNotifier) Connector.open(sConnectionURL);

我不是Java专家,但据我所知,这个段应与登记的名称obexName的SPP服务,并开始监听通过UUID myUUID传入连接。这工作按预期。

I am no java expert, but as far as I know, this snippet should register an SPP service with the name obexName and start to listen for incoming connections via the UUID myUUID. This works as intended.

当设备配对到手机上运行Java MIDlet时,它会设置一个位发送到SPP与手机上的UUID或不发送的。如果它不能找到与配对期间的UUID任何SPP,它将尝试使用正常的OBEX代替连接到电话。

When the device is pairing to the phone running the java midlet, it will set a bit to send to an SPP with the UUID on the phone or not send at all. If it cannot find any SPP with the UUID during the pairing, it will try to connect to the phone using normal OBEX instead.

这是版本2.1 UPDATE1的技术,我不能在Android手机上做的工作,既不是HTC Hero的,也不是HTC Desire的,无论是。不管我如何努力,手机只有在连接到手机上,而不是根据需要的应用程序。

This is the technique I cannot make work on an android phone, neither an HTC Hero, nor an HTC Desire, both with version 2.1-update1. No matter how I try, the phone is only connecting to the phone, and not to the application as desired.

我创建了一个类很像developer.android.com的例子:

I created a class much like the example on developer.android.com:

private class AcceptThread extends Thread
{
    private final BluetoothServerSocket __serverSocket;

    public AcceptThread()
    {
        BluetoothServerSocket tmpSocket = null;

        trace("Creating AcceptThread");
        try 
        {
            trace("Starting to listen");
            tmpSocket = _bluetoothAdapter.listenUsingRfcommWithServiceRecord(obexName, myUUID);
            trace("Listening successful");
        } 
        catch (Exception e) 
        {
            trace("Listening NOT successful");
            // TODO: handle exception
        }
        __serverSocket = tmpSocket;
        trace("AcceptThread created");
    }

    public void run()
    {
        BluetoothSocket socket = null;
        trace("AcceptThread started");
        while(true)
        {
            try 
            {
                trace("Waiting for socket acceptance");
                socket = __serverSocket.accept();
                trace( "Socket accepted");
            } 
            catch (Exception e) 
            {
                trace("Error when accepting socket: " + e.getLocalizedMessage());
                break;
                // TODO: handle exception
            }
            if (socket != null)
            {
                synchronized (BTTransfer.this)
                {
                    trace("Socket exists");
                    try
                    {
                        __serverSocket.close();
                        trace("Socket successfully closed");
                    }
                    catch (Exception e) {}
                    break;
                }
            }
            trace("Socket does not exist");
        }
    }

    public void cancel()
    {
        try
        {
            __serverSocket.close();
        }
        catch (Exception e) {}
        trace("AcceptThread cancelled and Socket successfully closed");
    }
}

有关code点评:
跟踪功能是一个同步的功能喂养文字处理程序对象,使UI信息。
该应用程序是故意没有做任何事情,但关闭连接成功之后的连接。
该应用程序达到等待套接字接受,但在那之后从未跟踪。

Comments about the code:
The trace function is a synchronized function feeding text to the Handler object, giving the UI information.
The application is knowingly not doing anything but closing the connection after a successful connection.
The application reaches "Waiting for socket acceptance" but never the trace after that.

我有一台PC的.NET应用程序,可以伪装成设备,并使用它完美的作品正确的UUID,但随后的电脑已经配对到手机上,而没有一点说,它应该发送超过正常OBEX如果找不到指定的一个。

I have a PC .NET application that can disguise itself as the device, and by using correct UUID it works flawlessly, but then the PC is already paired to the phone, and do not have the bit saying it should send over normal OBEX if it cannot find the specified one.

我一直在与这好几天了,并不能拿出一个解决方案。有没有人在那里有什么想法?

I have been working with this for several days, and can not come up with a solution. Does anyone out there have any ideas?

在前进,
谢谢  / Trygg

Thanks in advance,
/Trygg

使用我的意思是之后的第二个消息:

With the second message I mean following:

在设备联系人电话,有在下拉菜单中讲述一个设备接触的通知。几秒钟后(取决于文件大小)的文件传输,并有一个第二通知,告诉该文件被发送。这是第二个消息。

When the device contacts the phone, there is a notification in the drop down menu telling a device is contacting. A few seconds later (depending on the file size) the file is transferred, and there is a second notification telling the file is transmitted. This is the second "message".

由于我听从设备断开连接,和客户,然后通过我的计划已经知道,文件传输,这第二份通知是完全没有用的。不过,它将设备发送文件到手机,每次上来了。

Since I listen for the disconnection from the device, and the customer then through my program already knows that the file is transmitted, this second notification is utterly useless. Still, it will come up every time the device sends files to the phone.

在我们的传奇和英雄的测试中,我们从来没有来到第二个通知,但。这就是这些手机会失败。第一个通知来了,那么没有任何东西,设备,几秒钟后返回一个错误。

In our tests on Legend and Hero, we never come to the second notification, though. This is where those phones fail. The first notification comes, then nothing, and the device returns an error after a few seconds.

希望这有助于澄清我的意思。

Hope this helps to clarify what I meant.

/ Trygg

我没有得到这个工作,但做那种一种解决方法。我registerad对事件BluetoothDevice.ACTION_ACL_DISCONNECTED一个BroadcastReceiver,然后检查什么设备已断开。如果是我的我搜索了蓝牙收件箱中的文件。

I did not get this working, but made sort of a workaround. I registerad a BroadcastReceiver on the event BluetoothDevice.ACTION_ACL_DISCONNECTED and then checked for what device was disconnected. If it was "mine" I searched for the files in the bluetooth inbox.

我从设备说,它不会工作还没有制造商的消息,但他们正在研究一个新的固件。这就是为什么我没有在这里活跃的,也没有工作了一个更好的解决方案。

I got a message from the manufacturer of the device saying that it will not work yet, but they are working on a new firmware. This is why I haven't been active here nor worked for a better solution.

推荐答案

为了保险起见,你设置的Andr​​oid清单正确的权限?

Just to be sure, did you set the right permissions in the Android manifest?

这篇关于Android的RFCOMM与OBEX推不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆