[英]How to know if the calling intent is running in background or foreground?
I am using calling phone intent in Android as follows: 我正在Android中使用电话意图,如下所示:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+Uri.encode(phone_num.trim())));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);
The package name is com.android.incallui
. 包名称为
com.android.incallui
。 I want to know if the calling GUI is running in background or foreground. 我想知道调用GUI是在后台还是在前台运行。 Hence, I make a function
checkcallingGUI
, it will return true if the calling GUI is running in the foreground, and false if the calling phone is running in the background. 因此,我创建了一个函数
checkcallingGUI
,如果调用方GUI在前台运行,它将返回true;如果调用方电话在后台运行,则将返回false。 Is it possible to check it? 可以检查吗? Thank all
谢谢大家
you need to register a listener
on TelephonyManager
call states ( IDLE
, OFFHOOK
, RINGING
), and use the last received state to know if a call is currently in progress or not. 您需要在
TelephonyManager
呼叫状态( IDLE
, OFFHOOK
, RINGING
)上注册一个listener
,并使用最后收到的状态来了解当前是否正在进行呼叫。
Use this method to register a listener: https://developer.android.com/reference/android/telephony/TelephonyManager.html#listen(android.telephony.PhoneStateListener, int) 使用此方法注册侦听器: https : //developer.android.com/reference/android/telephony/TelephonyManager.html#listen(android.telephony.PhoneStateListener,int)
Read about possible stated and their meaning here: https://developer.android.com/reference/android/telephony/TelephonyManager.html#CALL_STATE_IDLE 在此处阅读有关可能的陈述及其含义的信息: https : //developer.android.com/reference/android/telephony/TelephonyManager.html#CALL_STATE_IDLE
And see complete code here: https://stackoverflow.com/a/14537914/819355 并在此处查看完整的代码: https : //stackoverflow.com/a/14537914/819355
EDIT 编辑
You can use the KeyguardManager service to check if the device is currently locked/secure, see this method: https://developer.android.com/reference/android/app/KeyguardManager.html#isKeyguardLocked() 您可以使用KeyguardManager服务来检查设备当前是否被锁定/安全,请参见以下方法: https : //developer.android.com/reference/android/app/KeyguardManager.html#isKeyguardLocked()
If i'm not mistaken, if the call-state is not IDLE, and the keyguard is enabled, you'll get the full screen UI, if not, it should be in the background. 如果我没记错的话,如果通话状态不是IDLE,并且启用了键盘锁,那么您将获得全屏UI,如果没有,则应在后台。
Try something like this: 尝试这样的事情:
KeyguardManager kg = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
if (kg.isKeyguardLocked()) {
// If telephony-state is also not IDLE, then the call UI should be full screen.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.