简体   繁体   中英

Android onSystemUiVisibilityChange is never called

Using the code verbatim from https://developer.android.com/training/system-ui/visibility.html in an app on a Google Nexus 4 (OS 4.4), and the onSystemUiVisibilityChange callback is never invoked. I might be seriously not understanding the conditions when this is to be invoked. I open up another app on the device that is in full screen mode and the status bar is hidden. Callback not invoked. Is this only meant for use with my own app?

What I'm really trying to do is detect if the status bar is displayed so I'll know I can post a notification with a ticker text that I know a user will see. If they're in a full screen app, they won't see my ticker text and that would not be ideal for me.

I don't think you will receive callbacks if you close your own app and open another one, particularly if this listener is being attached to one of your View s, because your views will be detached from the window when your activity leaves the foreground. Even the example use case they mention below that suggests it's meant to be used while your activity is on screen:

It's generally good practice to keep your UI in sync with changes in system bar visibility. For example, you could use this listener to hide and show the action bar in concert with the status bar hiding and showing.

With regard to your concern that your app's notifications won't be seen because the status bar is hidden: I find it hard to believe that this problem is not solved within the Android framework if they allow any app to hide system UI. Perhaps you can make your notification vibrate the device as well so that the user gets some other kind of feedback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM