HeadsetDetection-PhoneGap-Plugin
HeadsetDetection-PhoneGap-Plugin copied to clipboard
Ionic2
I would like to know if it works on Ionic2.
That's still Cordova, so why wouldn't it?
I figured how to make it work. Jolly good show.
Hi @EddyVerbruggen
I seem to be having some more issues. In a page, I am trying to use a function in typescript:
setHeadSetDetected(){
this.platform.ready().then(() => {
(<any>window).plugins.HeadsetDetection.detect(function (detected) {
alert(detected);
});
});
}
and call it in view like:
<button ion-button full color="primary" *ngIf="status == 'null'" (click)="setHeadSetDetected()">Detect Headphones</button>
I keep getting this error when I run on a real device:
TypeError: Cannot read property 'HeadsetDetection' of undefined
What do you think is wrong here?
Hi @sonoftheweb
This works for me.
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController) {
this.audioInit();
}
audioJackStatus(){
console.log('checking headphone');
try {
(<any>window).HeadsetDetection.detect(function(detected){
if(detected){
alert('Headphone connected')
}
else{
alert('No Headphone Found.')
}
})
} catch (error) {
alert(error);
}
}
audioInit(){
try {
document.addEventListener('deviceready', function() {
(<any>window).HeadsetDetection.registerRemoteEvents(function(status) {
switch (status) {
case 'headsetAdded':
alert('Headset connected');
break;
case 'headsetRemoved':
alert('Headset removed');
break;
};
});
}, false);
} catch (error) {
alert(error);
}
}
}
Git Repo https://github.com/Nayan014/headphone-ionic3