How to set full screen on android 4.4

I built my game on android 4.4 Kitkat. But i can’t set it to full screen. Someone can show m how to set full screen , please.

Maybe your phone’s screen size is bigger than your game’s resource size. If your game run good in 960*640.
invoke this function opengl_view->setDesignResolutionSize(960, 640, kResolutionFixedWidth);
there are some other ResolutionPolicy you can set. choose a best one. then the game will scale to fit your phone’s screen. you don’t need to worry about the position conversion, just the same in 960*640.

You do this by adding code from https://developer.android.com/training/system-ui/immersive.html in your main java activity class. This applies to cocos2d-x 2.x so not sure how to add it for 3.x yet. Your activity class would then look like this for example:

public class YourApp extends Cocos2dxActivity
{
    private Cocos2dxGLSurfaceView glSurfaceView;

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState); 
    }

    public Cocos2dxGLSurfaceView onCreateView()
    {
        glSurfaceView = new Cocos2dxGLSurfaceView(this);

        this.hideSystemUI();

        // create stencil buffer
        glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);

        return glSurfaceView;
    }

    public void onWindowFocusChanged(boolean hasFocus)
    {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus)
        {
            this.hideSystemUI();
        }
    }

    private void hideSystemUI()
    {
        // Set the IMMERSIVE flag.
        // Set the content to appear under the system bars so that the content
        // doesn't resize when the system bars hide and show.
        glSurfaceView.setSystemUiVisibility(
                Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_STABLE 
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }

    static
    {
        System.loadLibrary("cocos2dcpp");
    }     
}
1 Like

For Cocos2d-x v3 in proj.android/src/org/cocos2dx/cpp/AppActivity.java

/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011      Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
 
http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.cpp;

import org.cocos2dx.lib.*;

import android.os.Bundle;

public class AppActivity extends Cocos2dxActivity{

    private Cocos2dxGLSurfaceView glSurfaceView;

    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState); 
    }

    public Cocos2dxGLSurfaceView onCreateView()
    {
        glSurfaceView = new Cocos2dxGLSurfaceView(this);

        this.hideSystemUI();

        // create stencil buffer
        glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);

        return glSurfaceView;
    }

    public void onWindowFocusChanged(boolean hasFocus)
    {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus)
        {
            this.hideSystemUI();
        }
    }

    private void hideSystemUI()
    {
        // Set the IMMERSIVE flag.
        // Set the content to appear under the system bars so that the content
        // doesn't resize when the system bars hide and show.
        glSurfaceView.setSystemUiVisibility(
                Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_STABLE 
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }

    static
    {
        System.loadLibrary("cocos2dcpp");
    }     
}
5 Likes

Hi there!

I’m on 2.1.4 and tried immersive mode on my Nexus 5 (4.4.4) - works like a charm! )

Only one issue is recent apps thumbnail of my app is black rect now.
If I don’t use hideSystemUI() then all is fine and thumbnail shows last screenshot.

Any suggestions how to use immersive mode and have normal thumbnail in recent apps menu?

Thanks!

Just added this in to my Cocos 3.3 project, and if you want to maintain to backwards compatibility with older versions of Android:

  1. wrap setSystemUiVisibitiy in an SDK_INT test:

    if (Build.VERSION.SDK_INT >= 19) {
    glSurfaceView.setSystemUiVisibility(…)
    }

  2. Update your build target to API 19, and not above (21 breaks some C++ functions). On Mac do this in the terminal:

    android list target
    cd /path/to/proj.android
    android update project -p . -t ID
    android update project -p …/cocos2d/cocos/platform/android/java/ -t ID

where ID is the value from android list target corresponding to API 19

Also, I found that functions onCreate() and static{} can be omitted.

1 Like

hi…
i am new to android and i am having trouble hiding the soft keys…
My project is in Cocos2d-x C++ made on Xcode…
I then ported it to Android using the python command…

My code works perfectly on all android devices.
But i want to hide soft keys (show a black patch and white dots) instead (i am ok if i dont get fullscreen)
But the code should work on all versions of android from 4.2.2 Jelly Bean and above.
Can you please help?
I can share base code with you…
Thanks

Hii…
I tried your method and it does work partially (after some adjustments)

But I am using Sonar System’s Admob tutorial to integrate ads in the android build.
So in my case:
public class YourApp extends SonarFrameworks (NOT Cocos2dxActivity)
and the SonarFrameworks file extends Cocos2dxActivity

So in this case, how should i implement immersive mode?
Any help will be highly appreciated
Thanks

Unfortunately “immersive mode” was added in Android 4.4 so cannot be implemented in older versions.

Hi there,

I’m new to Cocos2Dx and trying to set the immersive mode for my Android App.

I added your code in the AppActivity of my game, but when I compile my project (using “cocos run” command) I get a compiling error for Android.

-compile:
[javac] Compiling 3 source files to *path*\proj.android\bin\classes
[javac] *path*\proj.android\src\org\cocos2dx\cpp\AppActivity.java:68: error: package Build does not exist
[javac]         if (Build.VERSION.SDK_INT >= 19)
[javac]                  ^
[javac] *path*\proj.android\src\org\cocos2dx\cpp\AppActivity.java:71: error: cannot find symbol
[javac]                 Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_STABLE
[javac]                                      ^
[javac]   symbol:   variable SYSTEM_UI_FLAG_LAYOUT_STABLE
[javac]   location: class Cocos2dxGLSurfaceView
.... //AND SO ON FOR ALL THE SETTINGS ON glSurfaseView.setSystemUiVisibility()

Build fails, and I’m really confused on what I’m doing wrong!

[Using Windows 7 + Visual Studio + Cocos Command Line tool to compile and build]

Hope someone can help!

Include

import android.os.Build;
1 Like

Thank you, importing the Build package solved the first error!

Too bad that the errors relating to Cocos2dxGLsurfaceView are still there… I really don’t know how to tell AppActivity where to look for Cocos2dxGLSurfaceView!

It would be awesome to have some kind of link with an in depth analysis of Cocos+Android integration…

If you use SonarSystem’s Cocos-Helper, try this
/proj.android/src/org/cocos2dx/cpp/AppActivity.java

/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011      Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
 
http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.cpp;

import android.os.Build;
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
import sonar.systems.framework.SonarFrameworkActivity;


public class AppActivity extends SonarFrameworkActivity
{
	private Cocos2dxGLSurfaceView glSurfaceView;

    public Cocos2dxGLSurfaceView onCreateView()
    {
        glSurfaceView = new Cocos2dxGLSurfaceView(this);
        this.hideSystemUI();
        glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);

        return glSurfaceView;
    }

    public void onWindowFocusChanged(boolean hasFocus)
    {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus)
        {
            this.hideSystemUI();
        }
    }

    private void hideSystemUI()
    {
        if (Build.VERSION.SDK_INT >= 19) {
	        glSurfaceView.setSystemUiVisibility(
	                Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_STABLE 
	                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
	                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
	                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_HIDE_NAVIGATION
	                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_FULLSCREEN
	                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
	    }
    }
}

Hi there,
I got the same errors as Qtro. Compiler tell that class Cocos2dxGLSurfaceView doesn’t has layout symbols (SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN,…). I thought we missed some libraries and tried include all of librabies, but it still failed. I don’t know Java. How could I got documentation about Cocos2dxGLSurfaceView to fix that.

Hope someone can help!

@Arman11 @slackmoehrle when i use textfieldwithttf navigation bar is comes up and not hide .please provide me a solution.

You should use the latest version cocos2dx 3.12 , That version has updated hide virtual button by default.