访问Android的OBEX服务器和读取数据(Access Android's OBEX s

2019-09-18 10:21发布

我想知道,如果它可以读取数据(联系人,未接电话等),从与Bluecove窗户Android的OBEX服务器。 我试图从窗户下面的代码,但它返回OBEX_HTTP_NOT_ACCEPTABLE连接时。 设备地址和渠道是正确的,因为我可以告诉大家,因为运行此测试时,机器人会弹出一个对话框,询问我是否允许其他设备访问它的针数。 谢谢!

码:

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();
        }

    }
}

logcat的:

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

Answer 1:

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

头部应设置与值pbap_target字节数组的靶。



Answer 2:

clientSession ”连接需要一个目标报。



文章来源: Access Android's OBEX server and read data