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.

Jan Slominski
  • 2,968
  • 4
  • 35
  • 61
  • 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". – AlwaysTalkingAboutMyDog Apr 09 '22 at 07:11
  • @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. – Jan Slominski Apr 09 '22 at 11:48

1 Answers1

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.

samygj
  • 1
  • 2