cordova-plugin-background-mode icon indicating copy to clipboard operation
cordova-plugin-background-mode copied to clipboard

Capacitor Run

Open alicarlo opened this issue 10 months ago • 0 comments

I hope the information is useful to you.

I have used this plugin in Córdoba without problems, this time I use it in a capacitor, I will attach the steps to make it run

npm i cordova-plugin-background-mode --force
npm install cordova-plugin-background-mode@github:Mforcen/cordova-plugin-background-mode#2b9a4de --force

npm i cordova-plugin-device --force ionic cordova plugin add cordova-plugin-device

CAP1

You must manage the permissions yourself, you can use a plugin like android permissions or guide the user to the configuration to enable them, normally this plugin is used to obtain the gps in the background, the gps will only ask for permissions to use with the app in foreground, but by adding the following permissions in your android manifest, you will be able to see the allow all time permission on your location

Allow all the time

image

Permissions on your android manifest

image

The permission must be added to disable battery saving for the background mode to work, when adding the permission the application will automatically request it

At this point the previous steps should work in cordova as well, in capacitor it generates an error in getView() when reopening the app

image

A temporary solution is to modify a line in the plugin. I attach the commit link.

https://github.com/katzer/cordova-plugin-background-mode/commit/0bc885ca34c2d602f7a373d316dc1ffc67cf4d83.

image

With the previous notes you should be able to run the background, v5 capacitor is being used, the tests were done with Android 10 and Android 13

alicarlo avatar Apr 25 '24 17:04 alicarlo