Search code examples
codenameone

Native code (hide navigation bar on Android) which compiles well but doesn't work in Codename One


I need to implement a native code in Codename One to hide an app navigation bar (the bar under the app which have the back and home buttons). I tried to use native interface in Codename One to do that. My code compiles very well but when I execute on the device, nothings happen. Here is my native implementation code:

public class NavigationBarImpl {
    public void masquerNavigationBar() {
        
        //        com.codename1.impl.android.AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() {
        //        public void run() {
                    android.view.View decorView=com.codename1.impl.android.AndroidNativeUtil.getActivity().getWindow().getDecorView();           
                    int uiOptions=android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|android.view.View.SYSTEM_UI_FLAG_FULLSCREEN;
                    decorView.setSystemUiVisibility(uiOptions);
        //        }
        //        });
                
            }
    
        public boolean isSupported() {
            return false;
        }
    
    }

In my main class, I call the function like this:

Button b=new Button("Masquer Navigation Bar");
        b.addActionListener(evt->{
            NavigationBar nBar=(NavigationBar)NativeLookup.create(NavigationBar.class);
            if(nBar==null) {
                throw new RuntimeException("Cette fonctionnalité n'est pas ENCORE supportée sur cette plateforme");
            }
            if(!nBar.isSupported() ){
                throw new RuntimeException("Cette fonctionnalité n'est pas supportée sur cette plateforme");
            }
            nBar.masquerNavigationBar();
        });

First, I tried to put the code in the native EDT. It doesn't work. Without putting it in the native EDT, It doesn't work too. I have no error and it compiles well. What am I doing wrong? Thanks!


Solution

  • It's hard to tell without debugging and you didn't include the code where you created the native interface but this looks like a mistake:

        public boolean isSupported() {
            return false;
        }
    

    It should return true.