FullScreen API Not Working in Android Studio Virtual Phone

4 weeks ago 31
ARTICLE AD BOX

I've recently been working on porting an HTML5 video game I built for Android devices as an app. I am using Android Studio to assist with development.

After some trial and error, I've been able to get everything working except for one aspect. In the video game, I use JavaScript's requestFullScreen() function to enter fullscreen mode on the canvas. Normally, this works on all web platforms that support the Fullscreen API. However, when the same application is running inside a WebView, fullscreen does not seem to activate.

Here is the code I am using for activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <WebView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/webView" /> </LinearLayout>

Here is the code I am using for MainActivity.java:

package com.nameofapp.notshared; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import android.webkit.WebChromeClient; import android.webkit.WebView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView webView=findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setSafeBrowsingEnabled(false); webView.getSettings().setAllowContentAccess(true); webView.getSettings().setAllowFileAccess(true); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setAllowFileAccessFromFileURLs(true); webView.setWebChromeClient(new WebChromeClient()); webView.loadUrl("file:///android_asset/index.html"); } }

I'm not very well versed in Java, so most of this code was written by following tutorials.

What am I missing?
What do I need to add in order to allow the Fullscreen API to function properly?

Read Entire Article