Read contacts using bluetooth

2019-07-23 14:58发布

问题:

I'm trying to read contacts from my mobile device using 32feet library and i'm having a bad request error when I try. The device is paired with my app. This is my code:

var item = (BluetoothDeviceInfo)listBox.SelectedItem;
Task.Run(() =>
{
    item.Update();
    item.Refresh();

    item.SetServiceState(BluetoothService.PhonebookAccess, true);

    if (OBEXOpenStream(item.DeviceAddress.ToString()))
    {
        if (OBEXConnect())
        {
            string tName = "";
            string tType = "text/x-vCard";
            string tFileContent = "";
            int result = OBEXRequest("GET", tName, tType, tFileContent);

            item.ShowDialog();
        }
    }
    OBEXCloseStream();

});

I dont know if there are another ways to get the contacts using OBEX.

回答1:

Maybe you made a mistake when you have to send a empty name header for the request. The variable tName should be null not "", as "" is 0x00 in bytes, not empty name header. The library will send the size of the name header as0x0004, not 0x0003, which is required for your vCard request. This is a common mistake, and I commited it too :)

OR Why do you give tFileContents parameter? It is not necessary as I know. You may have to delete the parameter. According to IRDA spec, it is not needed.

Sorry for poor English and I hope this answer helped a lot.