BLE connection to Android mobile phone

Hi,

I'm using NRF52840 to connect to an Android mobile phone.

The application scans for advertisement and when the NRF device starts advertising - connection is established.

The problem is that after bonding - connection isn't always established when advertising starts. Only when the application is open on Android mobile phone, everything works.

Is there any definition on NRF device that can solve that problem? To make sure the Android will connect on every advertisement after bonding?

Thanks!

  • Hi,

    I've read about ble_app_hids_keyboard - can you please tell me what is special about it?

    Can it be related to the ability to connect to a mobile phone when the app is not open?

    Thanks!

  • The HID profile is supported natively by Android. No other app is required.

  • Hello,

    The automatic connection can be established in several ways. After bonding, the device could advertise directly, which should trigger Android reconnecting to the device. But then, you should have an app ready to take over the connection. For HID profiles, like keyboard and mouse, that is not needed, as it's supported natively since KitKat. Other profiles need to have an app, and the app need to be running or woken up by the system.

    On Android O and newer, you may scan with PendingIntent, which will allow your app not to have any long running service. When the device is found, the system can wake up your app by calling a broadcast, or perhaps starting a service, that should connect to the device.

    You may also use a background service that does the scanning, but those may be killed if the service is not displaying a notification (isn't promoted to foreground service). Have a look at https://developer.android.com/about/versions/oreo/background.

    Nordic offers Android Scanner Compat Library which can emulate scanning with PendingIntent for older platforms, but we highly recommend setting minSdk to Android O, as this is way more battery efficient than what the compat library can deliver.

  • Hi Aleksander, thank you for your answer!

    Can you please explain a little bit more about the HID profile?

    What does it do? Can it help me with my issue? How can I define it on my NRF code?

    Thanks!

  • HID stands for Human Interface Device, which is a keyboard, mouse, a joystick, etc. Input from such devices is supported by Android, so you may connect your keyboard to the phone/tablet and use it instead of soft keyboard (displayed on the screen). The example you mentioned, ble_app_hids_keyboard, demonstrates how to implement such. But if you're not working on such device, you should rather look into how this sample is advertising. Have a look at advertising_init method (if you're using nRF5 SDK) and see that the keyboard sample is using directed advertising.

    I'm now trying to implement the same in Proximity sample, which is not natively supported by Android, and see it the phone connects to it automatically as well without any app asking for it.

Related