Question about background service Bip 6 #427
Unanswered
brenopenalmeida
asked this question in
Q&A
Replies: 2 comments 1 reply
-
Try this example. Make sure to add Bip 6 into it before running. |
Beta Was this translation helpful? Give feedback.
1 reply
-
@silver-zepp Even if an application is running in the background, the battery settings always say that 0 applications are running in the background. Is it a bug or do I misunderstand what should be displayed in this line? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I’m creating an app to run on the Bip 6. The app is simple—just for experimenting with background execution. When it’s launched for the first time, a prompt appears asking to allow background operation; after granting permission, the Bip 6’s App Settings correctly show that the app is allowed to run in the background. However, when I check the Battery options, it reports that no app is running in the background, and yet if I launch the app again after it’s been sent to the background, it still receives the notification “service iniciado true.”
Below is the full script. Could someone help me?
app-service/bg.js
import { HeartRate } from '@zos/sensor'
AppService({
onInit() {
console.log('BG Service onInit: iniciando sensor HR')
this.hr = new HeartRate()
this.hr.onChange(info => {
console.log(
HR = ${info.bpm} bpm
)})
this.hr.start()
},
onDestroy() {
console.log('BG Service onDestroy: parando sensor HR')
if (this.hr) this.hr.stop()
}
})
page/index.js
import hmUI from '@zos/ui'
Page({
onInit() {
console.log('index onInit: serviço BG já iniciado (ou em execução)')
}
})
page/start.js
import { queryPermission, requestPermission } from '@zos/app'
import * as appService from '@zos/app-service'
import hmUI from '@zos/ui'
const BG_PERM = ['device:os.bg_service']
const SERVICE_URL = 'app-service/bg'
Page({
onInit() {
// 1) checa se já temos permissão
const [status] = queryPermission({ permissions: BG_PERM })
if (status === 2) {
// ok, já está autorizado
this._startBgService()
} else {
// pede permissão
requestPermission({
permissions: BG_PERM,
callback: ([res]) => {
if (res === 2) {
this._startBgService()
} else {
hmUI.showToast({ text: 'Permissão negada' })
}
}
})
}
},
_startBgService() {
hmUI.showToast({ text: 'Iniciando serviço BG…' })
appService.start({
url: SERVICE_URL,
param: '',
complete_func: info => {
hmUI.showToast({ text:
Serviço iniciado: ${info.result}
})// fecha a UI imediatamente
hmUI.exit()
}
})
}
})
app.js
// app.js
App({
onCreate(options) {
console.log('App criado');
},
onDestroy() {
console.log('App destruído');
}
});
app.json
{
"configVersion": "v3",
"app": {
"appId": 20001,
"appName": "BG Only",
"appType": "app",
"version": { "code": 1, "name": "1.0.0" },
"icon": "icon.png",
"vender": "zepp",
"description": "Exemplo mínimo BG"
},
"permissions": [
"device:os.bg_service",
"data:user.hd.heart_rate"
],
"runtime": {
"apiVersion": { "compatible": "4.0", "target": "4.0", "minVersion": "4.0" }
},
"targets": {
"common": {
"module": {
"page": { "pages": ["page/start"] },
"app-service": { "services": ["app-service/bg"] }
},
"platforms": [{"name":"bip6","deviceSource":9765121}],
"designWidth": 480
}
},
"defaultLanguage": "en-US"
}
link: https://github.com/brenopenalmeida/teste_segundo_plano_zepp_os.git
Beta Was this translation helpful? Give feedback.
All reactions