How to make a phonegap build app work in backgroun

2019-06-14 16:15发布

I need my app to work 24/7 recording the users location every 5 mins. It works fine while the phone is active but when it isn't the setInterval()'s strecth out to be up to 5x longer than they should.

Using phonegap build, how would I go about making the app work as it should in the background while the phone is idle?

1条回答
Bombasti
2楼-- · 2019-06-14 16:35

@Marty,
both Android and iOS and run in the background, but require an extension to the regular config.xml.

To be clear Android apps uses AndriodManifest.xml. iOS uses, preferences.plist

Both have the ability to go into background. However, in Cordova/Phonegap this is not available directly, you must make an extension. The best explaination are from Cordova and Phonegap Build.

From Phonegap Build: Start with: Config File Elements. You will need to add <gap:config-file> one for each, then you will also need to add to the first xml element, like this:

 <widget xmlns = "http://www.w3.org/ns/widgets"
        xmlns:android   = "http://schemas.android.com/apk/res/android"
        xmlns:gap   = "http://phonegap.com/ns/1.0"
        id          = "com.bsdmasterindex.googlemapexamples"
        version     = "1.0.0"
        versionCode = "10" >

The most important item being xmlns:android = "http://schemas.android.com/apk/res/android". This is only for android, of course.

Examples of using this are in my Demo Boiler plates for Phonegap Build - source available at git hub.

Three (3) Phonegap Build Boilerplates for For Android and iO

You will want to look at Boilerplate #2.

This article will help. 7 things you should know about Android Manifest xml file

If you have further question, I suggest you go to google groups. I will soon be dropping Stackoverflow from my readying list. I willl likely drop on Monday.

Jesse

查看更多
登录 后发表回答