How can I enter full screen mode with webview feature

2.2k views Asked by At

I have a website and I use App Inventor to create an Android app for my website. I have posts with html videos on it, but every time I enter the app to watch my videos in the app, I can't enter full screen mode!!

1

There are 1 answers

0
Chandima Samarakoon On

Solution for enabling full screen for Internet Videos when accessed in WebView for sites like Youtube or any other streaming site:

Let's say you have this variable and you used findViewById() in onCreate to set it up. We've also used mainActivity as a variable to refer to the activity that contains the webview.

Follow below instructions

WebView webView;

Activity mainActivity = this; // If you are in activity

Activity mainActivity = getActivity(); // If you are in fragment

Then follow this step

webView.getSettings().setJavaScriptEnabled(true); //Enable Javascript
webView.getSettings().setDomStorageEnabled(true); //enable local storage for WebView

webView.setWebChromeClient(new WebChromeClient()
        {
            private View mCustomView;
            private WebChromeClient.CustomViewCallback mCustomViewCallback;
            protected FrameLayout mFullscreenContainer;
            private int mOriginalOrientation;
            private int mOriginalSystemUiVisibility;

            public Bitmap getDefaultVideoPoster()
            {
                if (mainActivity == null) {
                    return null;
                }
                return BitmapFactory.decodeResource(mainActivity.getApplicationContext().getResources(), 2130837573);
            }

            public void onHideCustomView()
            {
                ((FrameLayout)mainActivity.getWindow().getDecorView()).removeView(this.mCustomView);
                this.mCustomView = null;
                mainActivity.getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
                mainActivity.setRequestedOrientation(this.mOriginalOrientation);
                this.mCustomViewCallback.onCustomViewHidden();
                this.mCustomViewCallback = null;
            }

            public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
            {
                if (this.mCustomView != null)
                {
                    onHideCustomView();
                    return;
                }
                this.mCustomView = paramView;
                this.mOriginalSystemUiVisibility = mainActivity.getWindow().getDecorView().getSystemUiVisibility();
                this.mOriginalOrientation = mainActivity.getRequestedOrientation();
                this.mCustomViewCallback = paramCustomViewCallback;
                ((FrameLayout)mainActivity.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
                mainActivity.getWindow().getDecorView().setSystemUiVisibility(3846);
            }
        });