当Messenger应用正在通话或想拨打电话时,如何检测Skype/电报/whatsapp通话? [英] How do I detect skype/telegram/whatsapp calls when my messenger app is in a call or wants to make a call?

查看:403
本文介绍了当Messenger应用正在通话或想拨打电话时,如何检测Skype/电报/whatsapp通话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以检测到进行中的Skype呼叫/电报/whatsapp/fb信使呼叫等或来电等,就像与电话管理器/监听器的常规电话一样?我想使用某种机制来检测来自我的应用程序的Skype/电报等正在进行的/传入的呼叫.我遇到了以下解决方案:在Android中检测Skype的呼叫,但不确定是否适用于所有通用Messenger应用.我是否可以实施骇客或任何种类的侦听器来检测到这些内容?任何想法都很棒.

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.

谢谢!

推荐答案

您可以使用 AudioManager#getMode() 返回当前音频模式,可以是以下其中一种:

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):普通音频模式:不响铃且未建立呼叫.

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

MODE_RINGTONE (0x00000001):铃声音频模式.

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

MODE_IN_CALL (0x00000002):在通话音频模式下.建立了电话通话.

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

MODE_IN_COMMUNICATION (0x00000003):在通信音频模式下.建立了音频/视频聊天或VoIP通话(API 11中已添加).

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

使用 AudioManager#getMode() ,您可以检查是否当前,任何其他应用程序都拥有类型为MODE_IN_COMMUNICATION音频焦点,并相应地处理您的呼叫.

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.我已经用 whatsapp Messenger 测试了它,并且可以正常工作!对于其他Messenger应用无法说相同的话.

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

这篇关于当Messenger应用正在通话或想拨打电话时,如何检测Skype/电报/whatsapp通话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆