androidandroid-6.0-marshmallowkiosk-modecosu

Is there possibility to hide back key icon from navigation bar in locktask/kiosk mode on Android?


I'm making Cosu application and it's running on locktask mode. I have found guides to make NavigationBar and ActionBar fully transparent and hidden but if user swipes from bottom or top of the screen it will show back button on bottom NavigationBar.

I have added code snippet that hides it again quickly.

/* Hides Navigation bar again if user swipes it visible */
@Override
protected void onResume() {
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
                new View.OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                    getWindow().getDecorView().setSystemUiVisibility(flags);
                    }
                });
    super.onResume();
}

Is there any way to actually change that back button icon or it's color to transparent using styles or something?? I have tried to find out information on this but what i have found is using extra applications to modify back button image.

I can disable back button event by using following code but doesn't hide it's visibility

@Override
public void onBackPressed() {
     // nothing to do here
}

Solution

  • You can add this dependency to you build.gradle(app):

    https://github.com/topjohnwu/libsu

    android {
        compileOptions {
            // This library uses Java 8 features, this is required
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    
    dependencies {
        ...
        implementation "com.github.topjohnwu.libsu:core:3.1.1"
        ...
    }
    

    After that, add this line to your build.gradle(project):

    repositories {
        maven { url 'https://jitpack.io' }
    }
    

    Then, you can use this function for hide all buttons on nav bar:

    private fun disable backButtonOnLockTaskMode(){
        Shell.enableVerboseLogging = BuildConfig.DEBUG
        Shell.setDefaultBuilder(
            Shell.Builder.create()
                .setFlags(Shell.FLAG_REDIRECT_STDERR)
                .setTimeout(10)
            ) 
        Shell.su("settings put secure sysui_nav_bar \"space;space;space\"").exec()             
    }
    

    In other hand, you can change the string in command, but the success in that command it depends on your lock task mode implementation:

    I hope it's help you!

    Greetings!