我正在编写一个基于sip
的呼叫应用程序。当有来电时,它的相应活动被触发并显示在锁定屏幕下方。但是用户无法了解通话...锁定屏幕出现一段时间并且屏幕关闭..即使通话仍然响铃...铃声在整个持续时间内都处于活动状态但是屏幕没有不显示来电UI。我需要找到一种方法来显示相应的用户界面,并在整个来电期间保持屏幕显示...
对于在整个来电期间保持屏幕开启的部分我正在使用唤醒锁......但我无法摆脱锁定屏幕......
我进行了研究,发现可以使用KeygaurdManager
或WindowManager.LayoutParams
以及FLAG_KEEP_SCREEN_ON
,FLAG_DISMISS_KEYGAURD
,FLAG_SHOW_WHEN_LOCKED
和FLAG_TURN_SCREEN_ON
等适当的标记来解锁电话...但是这些在我的情况下不起作用...我在下面的一个链接中读到,当手机密码/模式锁定时无法解锁手机......这就是为什么我无法解决的问题显示我想要的UI?如何接听来电?请建议我一些解决方案
我提到的链接是
How can I unlock the screen programmatically in Android?
How do I prevent an Android device from going to sleep programmatically?
unlock screen while in call android
Android: Turn screen ON and notify user
How to launch an activity when lock screen is enabled?
Android activity over default lock screen
Android Create An Activity That Float Over Lockscreen
Unlock Android phone programmatically?
How to display Activity when the screen is locked?
How to unlock the device when my activity will be launched programmatically?
Android: How to turn screen on and off programmatically?
How to show incoming call notification in android application
How to display Activity when the screen is locked?
How unlock and lock screen programatically in android
How to unlock the device when my activity will be launched programmatically?
How to notify SIP client when there is an incoming call on another phone
提前致谢。
答案 0 :(得分:1)
对我而言,以下代码运作良好。
@Override
protected void onCreate() {
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
keyguard = km.newKeyguardLock("MyApp");
}
//when we need to unlock screen
@Override
protected void onResume() {
keyguard.disableKeyguard();
}
@Override
protected void onPause() {
keyguard.enableKeyguard();
}
请记住同时添加权限
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
答案 1 :(得分:0)
FLAG_SHOW_WHEN_LOCKED适用于大多数手机。活动必须是不透明的(不是对话框)。您可能还需要FLAG_TURN_SCREEN_ON和FLAG_KEEP_SCREEN_ON
但是,在运行4.0.3的Galaxy Note上,它目前不适用于我。还不确定为什么......