How to detect incoming call?

Hi all,
is it possible to somehow detect incoming call during my app using? In app I can record speech and I want to stop the record on incoming call.

I have not found any solution yet…

Thanks for reply

Thanks, but if I am trying to use it I get the error Uncaught Error: Cannot find module "io.gvox.plugin.phonecalltrap"

I have it included in app.module.ts:

import {PhoneCallTrap} from "io.gvox.plugin.phonecalltrap";

providers: [
        PhoneCallTrap,
    ]

and also in my component ts file:

import {PhoneCallTrap} from "io.gvox.plugin.phonecalltrap";
constructor(){
PhoneCallTrap.onCall(function (state) {
            console.log("CHANGE STATE: " + state);

            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;
            }
        });
}

What is wrong please? :-/

There is no ionic wrapper so you need to use window.

declare var window:any;

...

if (window.PhoneCallTrap) {
      window.PhoneCallTrap.onCall(function(state) {
          console.log("CHANGE STATE: " + state);
          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;
          }
      });
}
2 Likes

Still have error Uncaught Error: Cannot find module "io.gvox.plugin.phonecalltrap" :-/

Wrong import?

EDIT: Remove from app.module.ts helped, but… If I come to page where I want to use it I have this error:
TypeError: Cannot read property 'onCall' of undefined

1 Like

did you test it on the Device?

Yes, With livereload.

Did you make it? I have the same doubt.

No. I am afraid that it is not possible with ionic. And I have more thinks like this :-/

Any news from you here?

Or anybody with any idea? thanks

So Android version is done. Finaly :slight_smile: . And what about iOS? Some plugin for it? Thanks

How did you manage to get it to work for Android? Detailed steps please.

Hi,
exactly like @danielmm1997 wrote above. And no imports for CallTrap plugin.

@danielmm1997 i need to get the incoming phone number so i can use a different contact list from the one in the phone. Its any way you can help me accomplish that?, i’m willing to compensate for the time efforts my email nextbars@gmail.com

window.PhoneCallTrap doesnot work as window object has no such property.

Can u please help me

hello concern,
in my case window.PhoneCallTrap doesnot work as window object has no such property.

Can u please help me

Hello team,

I want to call some function inside cases of below functions but it is not getting executed is there any way to call a function when phone phone state is ringing or idle or on-hook
if (window.PhoneCallTrap) {
window.PhoneCallTrap.onCall(function(state) {
alert("CHANGE STATE: " + state);
switch (state) {
case “RINGING”:
alert(“Phone is ringing”);
break;
case “OFFHOOK”:
alert(“Phone is off-hook”);
break;
case “IDLE”:
alert(“Phone is idle”);
break;
}
});
}

when the phone call is made application looses its state hence its goes in background so u will have to background plugin to keep the app running.

I had a similar problem. I couldn’t figure out how to properly install the plugin on my phone.