@gokujy wrote:
Hello, I want display caller number in incoming call using ionic 4, here my code.
home.ts
import { Component } from '@angular/core'; import { AndroidPermissions } from '@ionic-native/android-permissions/ngx'; declare var PhoneCallTrap: any; //phone calls declare var window: any; @Component({ selector: 'app-home', templateUrl: 'home.page.html', styleUrls: ['home.page.scss'], }) export class HomePage { constructor(private androidPermissions: AndroidPermissions) { this.checkPermissionCall(); } //phone calls checkPermissionCall() { this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.READ_PHONE_STATE).then( success => { //if permission granted this.phonecalls(); }, err => { this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.READ_PHONE_STATE). then(success => { this.phonecalls(); }, err => { console.log("cancelled") }); }); this.androidPermissions.requestPermissions([this.androidPermissions.PERMISSION.READ_PHONE_STATE]); } //phone calls phonecalls() { if (window.PhoneCallTrap) { window.PhoneCallTrap.onCall(function (state) { alert("CHANGE STATE: " + state); //var callObj = JSON.parse(state), ///state = callObj.state, this.callingNumber = state.incomingNumber; alert("callingNumber STATE: " + this.callingNumber); switch (state) { case "RINGING": console.log("Phone is ringing"); break; case "OFFHOOK": console.log("Phone is off-hook"); break; case "IDLE": console.log("Phone is idle"); break; } }); } } }
I did this, with this i am getting phone state like phone is ringing when someone call but how can i get number?
please help
Posts: 1
Participants: 1