简体   繁体   English

如何知道呼叫意图是在后台还是在前台运行?

[英]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呼叫状态( IDLEOFFHOOKRINGING )上注册一个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.

相关问题 如何知道我的应用程序是在前台还是后台,android? - How to know if my application is in foreground or background, android? 如何在BroadcastReceiver中知道App是否在前台运行? - How to know in BroadcastReceiver if App is running on foreground? 如何检查应用程序是否在BroadcastReceiver中的前台后台运行 - How to check app is running in background of foreground in BroadcastReceiver 如何调试在后台和前台运行的 android 应用程序 - How to debug android apps running in background and Foreground 如何检查Android应用程序是在后台运行还是在前台运行? - How to check if an Android application is running in the background or in foreground? 如何从上下文值中知道当前正在运行哪个活动? - How to know from context values which activity is currently running foreground? 如何将意图发送到正在运行的服务或后台活动? - How to send intent to running service or background activity? 如何知道应用程序是否在前台? - How to know if the application is in foreground? 知道活动是在前台运行还是在后台运行 - Knowing if activity is running on foreground or background 在后台运行Intent服务 - Running Intent Service in Background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM