I have been trying to sort this problem out for ages (I am a beginner).
I want to run javascript when the app is in the background. I have tried setinterval but this dies after a while (10mins) when the app goes into the background mode.
So I thought I need a service to run in the background which then calls the javascript. I found katzer/cordova-plugin-background-mode plugin (https://github.com/katzer/cordova-plu...).
This looked to be able to run js in the background. (it would be great if somebody could confirm this for me).
I then needed to add the plugin in my app. Below I have described the steps that I have followed, though it does not work.
Please help!.
I hope that this thread will help other appery users install 3rd party plugins as there is not much information on it.
I downloaded the plugin zip and then opened the BackgroundMode.java file. From here I used the following information to set up the up the following folder structure in appery source.
So it looked like this:
In the www folder, I uploaded the file background-mode.js
I then edited the background-mode.js file and inserted the following at the start of the file.
I was not sure about the last part (ie .BackgroundMode). This was used as I checked the cordova-plugin-background-mode plugin.xml file (below) and the name was BackgroundMode.
I then added }); to the end of the script in background-mode.js (see below).
All good so far?
I then edited the cordova_plugin .js file (in the lib folder) and added the following.
,
{
"file": "plugins/de.appplant.cordova.plugin.background/www/background-mode.js",
"id": "de.appplant.cordova.plugin.background.backgroundMode",
"clobbers": [
"backgroundMode"
]
}
So it looked like this.The information used here was sourced from the cordova-plugin-background-mode plugin.xml (see below)
6a. I then went to res xml config.xml and added the following code:
To the start of the file so that it looked like this:
6b. and at the end of the file I added the following:
Code: Select all
param name="android-package" value="de.appplant.cordova.plugin.localnotification.LocalNotification" param name="android-package" value="de.appplant.cordova.plugin.background.BackgroundMode"
So it looked like:
The information required for step 6 was sourced from the cordova-plugin-background-mode plugin.xml file (see below).
I then created the following folder structure and uploaded the following files from the zip that I downloaded.
I then went to AndroidManifest.xml. and added the following:
I was not sure where I should put it so I did it under the only other service in the file.
So it looked like this:This information was sourced from the plugin.xml file (see below)
The app compiled OK with no errors. I installed the app and tried to call the javascript at a time in the future. Unfortunately it did not work. When I checked my device to see which apps were running in the background, my app wasn’t showing.
Any help would be greatly appreciated.
Jimmy