You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { Component } from '@angular/core';
import { Platform,AlertController } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { HomePage } from '../pages/home/home';
import { AngularFire} from 'angularfire2'
import { LocalNotifications} from 'ionic-native';
import { AudioProvider } from 'ionic-audio';
import { FormBuilder } from '@angular/forms'; @component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage = HomePage;
audio;
notifications=[];
Alarmcheck;
//playSelectedTrack:any;
constructor(private FormBuilder:FormBuilder, private _audioProvider: AudioProvider,private AlertController:AlertController,platform: Platform,public af:AngularFire,) {
this.audio = new Audio();
this.audio.src='https://ia800406.us.archive.org/16/items/JM2013-10-05.flac16/V0/jm2013-10-05-t30-MP3-V0.mp3';
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();
var arr=[];
this.af.database.list('/notifications').subscribe(data=>{
console.log("firebase collection");
arr=data;
for(var i in arr)
{
if(arr[i].STATUS === 'ON')
{
var key=arr[i].$key;
console.log("ALARM CHECKED");
console.log(this.Alarmcheck);
if(this.Alarmcheck === undefined || this.Alarmcheck === 'OFF')
{
console.log("opened");
console.log(arr[i].STATUS);
LocalNotifications.schedule({
title: "Test Title",
text: "You have new notification",
at: new Date(new Date().getTime() + 5 * 1000),
sound:this.playSelectedTrack(),
})
LocalNotifications.on("click", (notification, state) => {
let alert = this.AlertController.create({
title: "Notification Clicked",
subTitle: "You just clicked the scheduled notification",
buttons: [{
text: "exit?",
handler: () => { this.pauseSelectedTrack(key) }
}]
});
alert.present();
});
}
}
}
})
});
}
schedule()
{
console.log("Notifications received");
LocalNotifications.schedule({
title: "Test Title",
text: "You have new notification",
at: new Date(new Date().getTime() + 5 * 1000),
sound:this.playSelectedTrack(),
})
My app is received Notifications based on condition When status is ON.Receive first notifications and backround play audio.when click on notification display alert and click the OK button.Pause this audio also update status OFF.and receive another notification does not play audio file.
How to fix this issue.
Kindly advice me,
Thanks
The text was updated successfully, but these errors were encountered:
Hi,
I am beginner in ionic 2.
Here is my JSON File
"notifications" : {
"0" : {
"FROM" : 1,
"MSG" : "Admin Saravanan has sent new circular (Message from admin) ",
"RECEIVE_TIME" : "2017-03-18 06:17:26",
"SEND_TIME" : "2017-03-17 02:38:01",
"STATUS" : "ON",
"TO" : "ALL",
"TYPE" : "EVENT"
},
"1" : {
"FROM" : 1,
"MSG" : "New visitor muruganantham.k.m checkin your flat.",
"RECEIVE_TIME" : "2017-03-23 06:33:06",
"SEND_TIME" : "2017-03-23 11:45:26 am",
"STATUS" : "ON",
"TO" : "2",
"TYPE" : "VISITORS"
}
}
Here is my app component.
import { Component } from '@angular/core';
import { Platform,AlertController } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { HomePage } from '../pages/home/home';
import { AngularFire} from 'angularfire2'
import { LocalNotifications} from 'ionic-native';
import { AudioProvider } from 'ionic-audio';
import { FormBuilder } from '@angular/forms';
@component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage = HomePage;
audio;
notifications=[];
Alarmcheck;
//playSelectedTrack:any;
constructor(private FormBuilder:FormBuilder, private _audioProvider: AudioProvider,private AlertController:AlertController,platform: Platform,public af:AngularFire,) {
this.audio = new Audio();
this.audio.src='https://ia800406.us.archive.org/16/items/JM2013-10-05.flac16/V0/jm2013-10-05-t30-MP3-V0.mp3';
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();
}
schedule()
{
console.log("Notifications received");
LocalNotifications.schedule({
title: "Test Title",
text: "You have new notification",
at: new Date(new Date().getTime() + 5 * 1000),
sound:this.playSelectedTrack(),
})
}
playSelectedTrack():any{
console.log("audio play");
this.audio.play();
}
pauseSelectedTrack(key):any{
console.log("audio Paused");
var form1 = this.FormBuilder.group({
STATUS:['OFF']
});
var value=form1.value;
console.log("Value");
console.log(form1.value);
this.af.database.list('/notifications').update(key,value)
// console.log(this.audio.pause);
this.audio.pause();
this.audio.src="";
this.Alarmcheck="OFF";
}
}
My app is received Notifications based on condition When status is ON.Receive first notifications and backround play audio.when click on notification display alert and click the OK button.Pause this audio also update status OFF.and receive another notification does not play audio file.
How to fix this issue.
Kindly advice me,
Thanks
The text was updated successfully, but these errors were encountered: