I'm currently using immersive mode (API 19) for one of my Activities as follows:
getWindow().getDecorView()
.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.INVISIBLE);
This hides the system buttons and notification bar until the user swipes for them back. This works fine, however I wish to detect when the user makes the buttons visible again. I've tried a OnSystemUiVisibilityChangeListener
but it does not trigger for this particular event.
Any ideas?
Some content is best experienced fullscreen without any indicators on the status bar or the navigation bar. Some examples are videos, games, image galleries, books, and slides in a presentation. This is referred to as immersive mode.
Non-sticky (normal) immersive mode — A user can exit immersive mode, by swiping in the system bars. Sticky immersive mode — A user can temporarily exit immersive mode by swiping in the system bars. Immersive mode is automatically re-entered after a short time (few seconds).
Download the PhotoSafe Fullscreen Immersive app from the Google Play Store. Similar paid apps, like Immersive Mode Manager, are available for free with Google Play Pass. Launch the app and tap I Agree. Tap the Off toggle in the top-right corner to turn it On.
From Android Developers video, when you're in immersive sticky mode, the app isn't notified.
Immersive sticky mode starts at 6:56 and around 7:25 Roman Nurik tells that the listener won't be triggered.
This is the video: http://youtu.be/cBi8fjv90E4?t=6m56s
I have found a solution that suits me even though it's not perfect. I set the UI visiblity to View.SYSTEM_UI_FLAG_IMMERSIVE
instead of View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
and when I receive the onSystemUiVisibilityChange
callback, I delay a message to an Handler to reset the UI Visibility. Here is the code :
private static final int FULL_SREEN_MSG = 10;
private static final long TIME_BEFORE_HIDE_UI = 2 * DateUtils.SECOND_IN_MILLIS;
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == FULL_SREEN_MSG) {
setFullscreen();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setFullscreen();
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
}
private void setFullscreen() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
mHandler.sendEmptyMessageDelayed(FULL_SREEN_MSG, TIME_BEFORE_HIDE_UI);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With