当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How does Facebook floating chat heads detect back button press inside a service?

问题描述:

I have a floating window that is connected to a service and I want to minimize it when back button is pressed.

I have searched here on stackoverflow and they say its not possible to capture button presses on a service, most notably here: Can the a backbutton press be detected from a service?

But I know the Facebook messenger floating chatheads can do this. If you maximize a conversation and press the back button, it minimizes the conversation and it doesn't pass the back button press on what app you are currently in.

I have tried putting a KeyListener on the root floating view but it doesn't seem to catch any keypresses.

 floatingView.setOnKeyListener(new View.OnKeyListener() {

@Override

public boolean onKey(View v, int keyCode, KeyEvent event) {

Log.e("motionevent",event.toString());

return false;

}

});

windowManager.addView(floatingView, params);

Suggestions on how FB Messenger does it?

分享给朋友:
您可能感兴趣的文章:
随机阅读: