从检测的Android服务全屏 [英] Detect full screen from service Android
问题描述
我需要检测从服务系统UI可见性(全屏)。我试图创建一个自定义视图,并添加 setOnSystemUiVisibilityChangeListener
但它永远不会被调用。
I need to detect the system ui visibility (full screen) from a service. I tried creating a custom view and adding setOnSystemUiVisibilityChangeListener
but it never gets called.
public void setListener() {
setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int i) {
Log.e(TAG, "onSystemUiVisibilityChange =" + i);
}
});
}
我从运行使用setListener
我的服务的 onStartCommand
。什么是错在这里?或者有没有其他的方法来检测时,系统UI是可见的还是不?感谢您的帮助。
I run setListener
from my service's onStartCommand
. What's wrong here? Or is there any other method to detect when the system ui is visible or not? Thanks for any help.
推荐答案
您可以添加一个预览(全高),并使用OnGlobalLayoutListener到listerner布局变化,onGlobalLayout检查view.getHeight与屏幕的最大Y点。
You can add one view (with full height) and use OnGlobalLayoutListener to listerner layout change, in onGlobalLayout check view.getHeight with max Y of screen.
if (mMaxY == helperWnd.getHeight()) {
//full screen
} else {
//none full screen
}
希望帮助你。
这篇关于从检测的Android服务全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!