Search code examples
androidpermissionsfullscreenandroid-permissions

How to ask permission or automatically set the phone's full screen on settings - android studio


I am trying to set my activity to full screen using this code below:

private void hideSystemUI() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | 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);

    }

But I am getting a black color navigation bar on certain phones because of the condition on settings -> display where certain phones need to permit apps to use a fullscreen mode. To address this issue I decided that I need to implement a permission checker when the activity inflates. If there is another way please tell me and I will try to implement it.

Edit: Here is the link of the conditions for phones that I am talking about: https://www.gottabemobile.com/how-to-enable-full-screen-apps-on-galaxy-s10/


Solution

  • In your manifest file put

    android:theme="@style/Theme.Design.NoActionBar" or

    android:theme="@style/AppTheme"  
    

    and in your activity call hideSystemUI(); before setting the content view like this :

    final int flags = 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;
    
        getWindow().getDecorView().setSystemUiVisibility(flags);
        setContentView(R.layout.activity_main);