语言

Menu
Sites
Language
Is it possible to get remote bt mac address of already connected device using native app?

If mobile and gear are connected, each mobile and gear can get remote bt mac? Not using SAP.

My application have to connect app of remote device with bt in any side, mobile or gear.  And user selection is not approved and two devices are connected arleady with bluetooth.

In this situation, how can my app in gear or mobile get already connected remote device's bt mac address?

 

查看选择的答案

响应

1 回复
Mark as answer
Armaan-Ul- Islam

You may like to check Bluetooth guide: native ,  there is a procedure stated to find the address of the device bonded.

/* Server address for connecting */
char *bt_server_address = NULL;
const char *remote_server_name = "server device";
 
bool
adapter_bonded_device_cb(bt_device_info_s *device_info, void *user_data)
{
    if (device_info == NULL)
        return true;
    if (!strcmp(device_info->remote_name, (char*)user_data)) {
        dlog_print(DLOG_INFO, LOG_TAG, "The server device is found in bonded device list. address(%s)",
                   device_info->remote_address);
        bt_server_address = strdup(device_info->remote_address);
        /* If you want to stop iterating, you can return "false" */
    }
    /* Get information about bonded device */
    int count_of_bonded_device = 1;
    dlog_print(DLOG_INFO, LOG_TAG, "Get information about the bonded device(%d)", count_of_bonded_device);
    dlog_print(DLOG_INFO, LOG_TAG, "remote address = %s.", device_info->remote_address);
    dlog_print(DLOG_INFO, LOG_TAG, "remote name = %s.", device_info->remote_name);
    dlog_print(DLOG_INFO, LOG_TAG, "service count = %d.", device_info->service_count);
    dlog_print(DLOG_INFO, LOG_TAG, "bonded?? %d.", device_info->is_bonded);
    dlog_print(DLOG_INFO, LOG_TAG, "connected?? %d.", device_info->is_connected);
    dlog_print(DLOG_INFO, LOG_TAG, "authorized?? %d.", device_info->is_authorized);
 
    dlog_print(DLOG_INFO, LOG_TAG, "major_device_class %d.", device_info->bt_class.major_device_class);
    dlog_print(DLOG_INFO, LOG_TAG, "minor_device_class %d.", device_info->bt_class.minor_device_class);
    dlog_print(DLOG_INFO, LOG_TAG, "major_service_class_mask %d.", device_info->bt_class.major_service_class_mask);
    count_of_bonded_device++;

    /* Keep iterating */

    return true;
}

ret = bt_adapter_foreach_bonded_device(adapter_bonded_device_cb, remote_server_name);
if (ret != BT_ERROR_NONE)
    dlog_print(DLOG_ERROR, LOG_TAG, "[bt_adapter_foreach_bonded_device] failed!");

if (bt_server_address != NULL)
    free(bt_server_address);