2

我想知道是否可以从带有 Bluecove 的 Windows 中从 Android 的 OBEX 服务器读取数据(联系人、未接来电等)。我从 Windows 尝试了以下代码,但它OBEX_HTTP_NOT_ACCEPTABLE在连接时返回。设备地址和通道是正确的,因为在运行此测试时,android 会弹出一个对话框,询问我是否允许其他设备访问它的联系人。谢谢!

代码:

import java.io.IOException;
import javax.microedition.io.Connector;
import javax.obex.*;

public class PBAPTest1 {

    public static void main(String[] args) {
        String deviceAddress = "001122334455";
        int channel = 19;
        String serverURL = "btgoep://" + deviceAddress + ":" + channel + ";authenticate=false;encrypt=false;master=false";

        System.out.println("Connecting to " + serverURL);

        ClientSession clientSession = null;
        Operation op = null;
        HeaderSet hdr = null;

        try {
            clientSession = (ClientSession) Connector.open(serverURL);
            hdr = clientSession.connect(clientSession.createHeaderSet());
            if (hdr.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) {
                System.out.println("Failed to connect: "
                        + hdr.getResponseCode()); // response: 198 OBEX_HTTP_NOT_ACCEPTABLE
                return;
            }
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }

        byte[] PBAP_TARGET = new byte[] { 0x79, 0x61, 0x35, (byte) 0xf0,
                (byte) 0xf0, (byte) 0xc5, 0x11, (byte) 0xd8, 0x09, 0x66, 0x08,
                0x00, 0x20, 0x0c, (byte) 0x9a, 0x66 };

        hdr.setHeader(HeaderSet.TARGET, PBAP_TARGET);
        hdr.setHeader(HeaderSet.NAME, "pb.vcf");
        hdr.setHeader(HeaderSet.TYPE, "x-bt/vcard-listing");
        try {
            op = clientSession.get(hdr);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

日志猫:

D/BluetoothEventLoop( 1551): Device property changed: XX:XX:XX:XX:XX:XX property: Connected value: true
D/BluetoothService( 1551): CONNECTION_STATE_CHANGE: XX:XX:XX:XX:XX:XX: 0 -> 2
D/Obex ServerSession( 1948): java.io.IOException: Software caused connection abort
D/BluetoothAdapterStateMachine( 1551): BluetoothOn process message: 52
D/BluetoothService( 1551): CONNECTION_STATE_CHANGE: XX:XX:XX:XX:XX:XX: 2 -> 0
D/BluetoothEventLoop( 1551): Device property changed: XX:XX:XX:XX:XX:XX property: Connected value: false
4

2 回答 2

2
hdr = clientSession.connect(clientSession.createHeaderSet());

标头应设置为值为 pbap_target 字节数组的目标。

于 2012-09-05T04:19:50.630 回答
0

" clientSession" connect 需要一个目标头。

于 2012-08-13T12:58:33.723 回答