Hide soft keys/navigation bar on Android

Hi,

I was trying to hide soft keys (navigation bar at the bottom) on android when the game launches.

I followed the post here

and my current code is like:


import org.cocos2dx.lib.*;
import android.os.Bundle;
import android.os.Build;

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.
    	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 // hide nav bar
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                | Cocos2dxGLSurfaceView.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    	}
    }

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

But on compiling and running it crashes the on my android 4.2.2 saying “Unfortunately my game as has stopped”
Though the post IS specifically for 4.4 but I think solution should exist for 4.2.2 as other games I’ve installed on my tablet does hide it.

Logs says:

08-15 23:42:53.278: D/jdwp(10038): sendBufferedRequest : len=0x55
08-15 23:42:53.286: D/dalvikvm(10038): open_cached_dex_file : /data/app/org.company.numbergame-1.apk /data/dalvik-cache/data@app@org.company.numbergame-1.apk@classes.dex
08-15 23:42:53.377: W/dalvikvm(10038): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/cocos2dx/cpp/AppActivity;
08-15 23:42:53.377: W/dalvikvm(10038): Class init failed in newInstance call (Lorg/cocos2dx/cpp/AppActivity;)
08-15 23:42:53.377: D/AndroidRuntime(10038): Shutting down VM
08-15 23:42:53.377: W/dalvikvm(10038): threadid=1: thread exiting with uncaught exception (group=0x411259a8)
08-15 23:42:53.409: E/AndroidRuntime(10038): FATAL EXCEPTION: main
08-15 23:42:53.409: E/AndroidRuntime(10038): java.lang.UnsatisfiedLinkError: Couldn't load cocos2dcpp from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.company.numbergame-1.apk"],nativeLibraryDirectories=[/data/app-lib/org.company.numbergame-1, /vendor/lib, /system/lib]]]: findLibrary returned null
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at java.lang.Runtime.loadLibrary(Runtime.java:359)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at java.lang.System.loadLibrary(System.java:514)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at org.cocos2dx.cpp.AppActivity.<clinit>(AppActivity.java:62)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at java.lang.Class.newInstanceImpl(Native Method)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at java.lang.Class.newInstance(Class.java:1319)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2223)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at android.app.ActivityThread.access$600(ActivityThread.java:156)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at android.os.Looper.loop(Looper.java:153)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at android.app.ActivityThread.main(ActivityThread.java:5299)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-15 23:42:53.409: E/AndroidRuntime(10038): 	at dalvik.system.NativeStart.main(Native Method)

Does anyone know the solution.

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

If you’re using this way, for version 4.4 KITKAT you should not run it on a virtual machine . For other versions , you replace

glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);

To

glSurfaceView.setEGLConfigChooser(8 , 8, 8, 8, 16, 0); // Emulator or Genymotion Emulator

1 Like