Languages

Menu
Sites
Language
bt_initialize() call by app?

Hello.

before useing bluetooth in tizne, app have to call bt_initialize().

Then bt_initialize() have to be called by each application or just one call in device?

If other app call bt_initialize() and the other app don't need to call bt_initialize()?

If so, how check other app call bt_initialize() arleady?

View Selected Answer

Responses

3 Replies
Yasin Ali

Hi,
To find remote Bluetooth devices, you can either discover them and bond with them, or
you can query the list of previously bonded devices.

See Code Hints(Discovery Process):

/* Classic Bluetooth */
ret = bt_adapter_start_device_discovery();
/* Bluetooth LE */
int bt_adapter_le_start_device_discovery(void);
if (ret != BT_ERROR_NONE)
    dlog_print(DLOG_ERROR, LOG_TAG, "[bt_adapter_start_device_discovery] failed.");

A Bluetooth device must be in a discovery mode (visible) for other devices to find it
and connect to it. If you want other devices to find your device, you must set the
device to be visible.

bt_adapter_visibility_mode_e mode;
int duration = 2;
bt_adapter_get_visibility(&mode, &duration);

You may also query the bonded device list.:

bool
adapter_bonded_device_cb(bt_device_info_s *device_info, void *user_data){
  ... .... ...
}
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);

Please check "Finding Other Devices" section of this link
https://developer.tizen.org/ko/development/guides/native-application/connectivity-and-wireless/bluetooth?langredirect=1

Hope it will help you.
If you find my post is helpful for you, please mark it as the Best Answer to promote this post to others.

An

Dear Yasin Ali,

Hello.  I think you mistake to answer question.  My question is about bt_intialize().

Please see content of post again.

Thank you.

Mark as answer
Yasin Ali

 bt_initialize() initializes the Bluetooth API. This function must be called before Bluetooth API starts.

From your original post "before useing bluetooth in tizne".

This understanding should be: "before useing bluetooth API in tizne".

From Your Post:

Then bt_initialize() have to be called by each application or just one call in device?

- If your application need to use bluetooth API then you need to use bt_initialize() everytime.

From Your Post:

If so, how check other app call bt_initialize() arleady?

- If you want to know, "How to check Bluetooth state: On/Off ?" querying above question then following snippet will help you.

#include <bluetooth.h>
#include <dlog.h> // for logging purposes

void
check_bluetooth_state() {
    bt_adapter_state_e bt_adapter;

 if(bt_initialize() == BT_ERROR_NONE) {

  if(bt_adapter_get_state(&bt_adapter) == BT_ERROR_NONE) {

   if(bt_adapter == BT_ADAPTER_ENABLED)
    LOGI("Bluetooth enabled");
   else
    LOGI("Bluetooth disabled");

  }
 }
 bt_deinitialize();
}

Hope you will find it helpful.

Ref: https://developer.tizen.org/ko/development/api-references/native-application?redirect=https://developer.tizen.org/dev-guide/3.0.0/org.tizen.native.mobile.apireference/group__CAPI__NETWORK__BLUETOOTH__MODULE.html#ga8ff11bde26c63e78c1fe3c376e21a28c