我需要从服务中检测系统ui可见性(全屏)。我尝试创建自定义视图并添加setOnSystemUiVisibilityChangeListener
,但它永远不会被调用。
public void setListener() {
setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int i) {
Log.e(TAG, "onSystemUiVisibilityChange =" + i);
}
});
}
我从我的服务setListener
运行onStartCommand
。这里有什么问题?或者有没有其他方法来检测系统ui何时可见?谢谢你的帮助。
答案 0 :(得分:1)
您写道:
......来自服务。我尝试创建自定义视图...
LearningDataAnalysis02.hs:22:38:
Couldn't match expected type ‘Either String b’
with actual type ‘a0 -> Either a1 b0’
Relevant bindings include
func :: [String] -> b (bound at LearningDataAnalysis02.hs:22:20)
applyToColumnInCSV :: ([String] -> b)
-> CSV -> String -> Either String b
(bound at LearningDataAnalysis02.hs:22:1)
In the expression: either Left Right . func . elements columnIndex
In an equation for ‘applyToColumnInCSV’:
applyToColumnInCSV func csv column
= either Left Right . func . elements columnIndex
where
columnIndex = getColumnInCSV csv column
nfieldsInFile = length $ head csv
records
= tail $ filter (\ record -> nfieldsInFile == length record) csv
elements ci = map (\ record -> genericIndex record ci) records
LearningDataAnalysis02.hs:24:20:
Couldn't match expected type ‘a0 -> [String]’
with actual type ‘[Field]’
Possible cause: ‘elements’ is applied to too many arguments
In the second argument of ‘(.)’, namely ‘elements columnIndex’
In the second argument of ‘(.)’, namely
‘func . elements columnIndex’
Failed, modules loaded: none.
中的自定义View
未添加到已绘制的视图层次结构中。这就是为什么不调用该方法的原因。在活动中,您可以执行Service
然后检查,但由于您没有引用可见布局,因此无法使用mRootView.add(mCustomView)
。
对于(hacky)解决方案,请参阅此答案:Receiving hidden status bar/entering a full screen activity event on a Service
如果Service
正在运行时可见Activity
,则有更多选项。您可以将Service
绑定到Service
,并将Activity
内的setOnSystemUiVisibility()
的更新发送到Activity
。
请参阅:http://developer.android.com/guide/components/bound-services.html
或者只是在UI状态发生变化时从Service
发送广播,Activity
会监听。
答案 1 :(得分:1)
您可以添加一个视图(全高)并使用OnGlobalLayoutListener进行listerner布局更改,在onGlobalLayout上检查view.getHeight,屏幕最大Y.
if (mMaxY == helperWnd.getHeight()) {
//full screen
} else {
//none full screen
}
希望帮助你