How to show a incoming call activity

只愿长相守 提交于 2020-01-16 11:27:24

问题


I'm developing an Video and Voice chat app.

What I need to do is to show some incoming call activity when an user try to call another user.

I'm already using Firebase Cloud Message to send push message warning the device that there is a call request.

But I'm facing a hard time trying to wake up the device and show in front of the lock screen the incoming call, so the user can accept or decline the call.

What I'm looking for is something like what Whats App does when you call some one.

Showing that when the device in unlocked and the app is up and running, it is not a problem.

But how can I archive this goal when the device is locked and black screen.


回答1:


I was also developing this kind of app and what i did is : I used some Flags for WindowManager on that particular activity that i have to show on the screen at the time of incoming call event.

Try adding the below code in OnCreate() method of the activity that you are intend to showing on the screen.

getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                    + WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                    | +WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | +WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 

And mention Following permissions in Manifest :

 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
 <uses-permission android:name="android.permission.WAKE_LOCK" />

Hope so,it helps you.!!



来源:https://stackoverflow.com/questions/39145992/how-to-show-a-incoming-call-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!