Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

android - How do I detect skype/telegram/whatsapp calls when my messenger app is in a call or wants to make a call?

I am wondering if there is a way I can detect a skype call/telegram/whatsapp/fb messenger call etc in progress or incoming call etc just like the regular phone call with telephony manager/listener? I would like to have some kind of mechanism that detects an ongoing /incoming etc call from skype/telegram etc for my app. I came across this solution :Call Detection for skype in android but not sure if it'll work for all generic messenger apps. Is there a hack or any kind of listener I can implement on my side that allows me to detect these? Any ideas would be awesome.

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the AudioManager system service and check for audio mode using AudioManager#getMode(). According to the docs, AudioManager#getMode() returns the current audio mode which can be one of following:

  • MODE_NORMAL (0x00000000): Normal audio mode: not ringing and no call established.

  • MODE_RINGTONE (0x00000001): Ringing audio mode. An incoming is being signaled.

  • MODE_IN_CALL (0x00000002): In call audio mode. A telephony call is established.

  • MODE_IN_COMMUNICATION (0x00000003): In communication audio mode. An audio/video chat or VoIP call is established (added in API 11).

Using AudioManager#getMode() you can check if any other app is currently holding an audio focus of type MODE_IN_COMMUNICATION and handle your call accordingly.

AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
final int mode = am.getMode();
if(AudioManager.MODE_IN_CALL == mode){
  // device is in a telephony call
} else if(AudioManager.MODE_IN_COMMUNICATION == mode){
  // device is in communiation mode, i.e. in a VoIP or video call
} else if(AudioManager.MODE_RINGTONE == mode){
  // device is in ringing mode, some incoming is being signalled
} else {
  // device is in normal mode, no incoming and no audio being played
}

P.S. I've tested this with whatsapp messenger and it works! Cannot say the same for other messenger apps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...