Martin
Martin

Reputation: 11

Reading phone contacts from input stream sended via bluetooth

I'm trying to read contacts from input stream but I always receive only eof and no data. Data should be in vCard format and I'm trying to only print them to console

public void dataDownload(final Connection connection) {
        Thread thread = new Thread(() -> {
            try {
                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 };
                ClientSession clientSession = connection.clientSession.firstElement();
                HeaderSet headerSet = clientSession.createHeaderSet();
                headerSet.setHeader(HeaderSet.TARGET, PBAP_TARGET);
                headerSet.setHeader(HeaderSet.NAME, "pb.vcf");
                headerSet.setHeader(HeaderSet.TYPE, "x-bt/vcard-listing");
                headerSet.setHeader(HeaderSet.APPLICATION_PARAMETER, new byte[]{(byte) 65535,0});
                HeaderSet resHeader = clientSession.connect(headerSet);
                int result = resHeader.getResponseCode();
                if (result != ResponseCodes.OBEX_HTTP_OK)
                {
                    System.out.println("Connection failed");
                    System.exit(2);
                }

                Operation operation = clientSession.get(headerSet);
                DataInputStream inputStream = operation.openDataInputStream();

                int data;
                while((data = inputStream.read()) != -1)
                    System.out.println((byte) data);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        thread.start();
}

this is the code to access them and I allowed on my phone that I'm trying it with(iPhone6). I'll be happy for any advice. But the app should be able to read contacts from any smarthphone with bluetooth.

Upvotes: 1

Views: 50

Answers (0)

Related Questions