Android Companion device pairing: how to use REQUEST_COMPANION_RUN_IN_BACKGROUND permission?
Asked Answered
I

1

14

I'm currently testing Android companion device pairing and I'm not sure how to benefit from the REQUEST_COMPANION_RUN_IN_BACKGROUND permission.

In one part of Google documentation is says:

After the device is paired, the device can leverage the REQUEST_COMPANION_RUN_IN_BACKGROUND and REQUEST_COMPANION_USE_DATA_IN_BACKGROUND permissions to start the app from the background. You might use this method of pairing devices for initial configuration of a BLE-capable smart watch, for example.

in the permission itself:

Allows a companion app to run in the background.

and in the CompanionDeviceManager documentation it says:

If your app needs to be excluded from battery optimizations (run in the background) or to have unrestricted data access (use data in the background) you can declare that you use the android.Manifest.permission#REQUEST_COMPANION_RUN_IN_BACKGROUND and respectively.

Can someone please explain (or point me towards some sample code) how to leverage this permission in order to run the app in the background? Ideally I would like trigger an action in the companion app from the paired Bluetooth LE peripheral device.

Isomer answered 12/1, 2021 at 12:56 Comment(2)
Bump again, @Jan did you get anywhere with this? Right now it looks like the CompanionDeviceService is being dropped right away after the background notifications are processed. I'm guess the easy solution is to create a foreground notification, but the permission REQUEST_COMPANION_RUN_IN_BACKGROUND literally sounds like "run, ongoing, in the background".Outfight
@Zzzach... I'm sorry, been working on this 1.5 years ago so honestly I don't remember what was the solution (switched jobs in the meantime). From what I can see the documentation has been updated.Isomer
C
0

As long as you have used CompanionDeviceManager to create an association, and declared REQUEST_COMPANION_RUN_IN_BACKGROUND in your manifest. You should be able to run your service in the background.

Cola answered 13/11, 2022 at 0:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.