I want the game that I'm making to run in immersive mode, but android studio doesn't recognize the flag immersive mode because I set my minimum API to 16, and I know immersive mode was added only in KitKat which is later on. Is there any way to have my app run in immersive mode without changing my minimum API?
2 Answers
Yes, it is possible, but of course this immersive mode will be only working on devices with KitKat and higher. This, what is weird on your side, is fact, that basing on your words, you cannot even get these flags like this:
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
(or part of them). If it is this way, then it is looking, that your compileSdkVersion is lower, than it should be. On start I would advise you to update compileSdkVersion to 22 (and also make targetSdkVersion also 22) (both things you will find in build.gradle)
When you will do this, and you would like to use these flags please in places, where you want to use immersive mode add conditions, that will be looking like this:
if (Build.VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
int UI_OPTIONS = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
getWindow().getDecorView().setSystemUiVisibility(UI_OPTIONS);
}
Then it should not mess on older OS.
(UPDATE: 2nd block of code was updated)

- 1,874
- 1
- 16
- 20
-
It turns out I was trying to flag it the wrong way. Until now I had it flagged fullscreen using this line: getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); I tried it now with the way you wrote it above and it recognized it but I couldn't make it work probably because I tried to replace it with the FLAG_FULLSCREEN I had up until now. Could you help me with putting it in the right way? Also how do I make the Code appear in a box like you did? – Tamir Edery Jul 18 '15 at 00:15
-
I updated my post. About code appearing - you can make this only in post (not in comment). When you will copy paste your code to TextField. then select it and on select '{}' icon in top part of TextField – Mateusz Pryczkowski Jul 18 '15 at 06:11
-
Thanks, I'm just a week into developing and I'm still struggling a bit so I really appreciate the help. – Tamir Edery Jul 18 '15 at 13:09
-
You're welcome. If my post helped you - please make my post as correct answer and vote up for it – Mateusz Pryczkowski Jul 18 '15 at 20:22
-
Marked it as correct, still don't have enough reputation to upvote though. – Tamir Edery Jul 18 '15 at 21:38
Just Paste this Function in Activity Class and you are done
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
View decorView = getWindow().getDecorView();
decorView.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);
}
}

- 2,654
- 1
- 14
- 14