enrecipes/app/ForegroundService.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

import { TimerNotif } from './shared/utils'
const superProto = android.app.Service.prototype
android.app.Service.extend('com.tns.ForegroundService', {
onStartCommand: function(intent, flags, startId) {
2021-05-25 14:32:53 +00:00
console.log('onStartCommand')
superProto.onStartCommand.call(this, intent, flags, startId)
2021-05-25 14:32:53 +00:00
return android.app.Service.START_STICKY
},
onCreate: function() {
2021-05-25 14:32:53 +00:00
console.log('onCreate')
superProto.onCreate.call(this)
this.startForeground(777, this.getNotification())
},
onBind: function(intent) {
return superProto.onBind.call(this, intent)
},
onUnbind: function(intent) {
return superProto.onUnbind.call(this, intent)
},
onDestroy: function() {
2021-05-25 14:32:53 +00:00
console.log('onDestroy')
this.stopForeground(true)
},
getNotification: function() {
return TimerNotif.getNotification(
{
bID: 'bringToFront',
cID: 'cti',
cName: 'Cooking Timer info',
description: `0 ongoing, 0 paused`,
nID: 777,
priority: -2,
sound: null,
title: 'EnRecipes is running',
},
this.getApplicationContext()
2021-05-25 14:32:53 +00:00
)
},
})