I want my application to show a progress bar when I start a download or upload. For that I’m using fileTransfer, ionic local notifications.The value of progress is given according to the change of a variable that receives the value of an observable. o update the notification I used the update method, but with each update it vibrates again.
NOTE: When the cell phone has volume it does not vibrate.
Follow code
import { ChangeDetectorRef, Component, } from '@angular/core';
import { ApiService } from '../api.service';
import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
import { Platform } from '@ionic/angular';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
cont = 0
aux = 0
constructor(
private apiService: ApiService,
private notificacao: LocalNotifications,
private platForm : Platform,
private changeDetectorRef : ChangeDetectorRef,
) {
this.apiService.getContObservable().subscribe(res => {
console.log('Novo Valor: ', res)
if (res == 1) {
this.cont = res / 100
this.aux = res
this.criarNoficacao()
} else if (res == 100) {
this.cont = 0
this.aux = 0
} else {
this.cont = res / 100
this.aux = res
this.notificacao.update({
id: 1,
sound: null,
vibrate : null,
progressBar: { value: this.aux }
});
}
})
}
enviar(){
this.apiService.incrementar()
}
criarNoficacao(){
let song;
if (this.platForm.is("android")) {
song = 'file://sound.mp3'
} else if (this.platForm.is('ios')) {
song = 'file://beep.caf';
} else {
song = null
}
this.notificacao.schedule({
id: 1,
title: 'Sync in progress',
text: 'Copied 2 of 10 files',
progressBar: { value: this.aux }
});
}
/* enviar(){
this.apiService.inserirDados(this.entrada) //do request
}
listar(){
this.apiService.listar();
}
limpar(){
this.apiService.limpar();
} */
}
1 post - 1 participant