I have a WebView based app that shows a WordPress website. I have in my website a few YouTube videos, and the problem is YouTube videos does not have full screen button. I looked for an answer to this and didn’t find anything on the web. Can someone help me? how can I make the YouTube videos have the option to play in full screen from my WebView?
Here is my MainActivity code:
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import com.delitestudio.pushnotifications.PushNotifications;
import com.loopj.android.http.*;
import cz.msebera.android.httpclient.*;
import cz.msebera.android.httpclient.impl.entity.StrictContentLengthStrategy;
public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getSimpleName();
private static final WebChromeClient webChromeClient = new WebChromeClient();
private static final WebViewClient webViewClient = new WebViewClient();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url;
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("fromPush")) {
url = "http://www.paotiptipon.co.il/%d7%9b%d7%a0%d7%99%d7%a1%d7%aa-%d7%94%d7%95%d7%a8%d7%99%d7%9d-2/%d7%a4%d7%95%d7%a1%d7%98%d7%99%d7%9d/";
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.loadUrl(url);
} else {
url = "http://paotiptipon.co.il/";
}
WebView myWebView = (WebView) this.findViewById(R.id.webView);
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebChromeClient(webChromeClient);
myWebView.setWebViewClient(webViewClient);
myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.getSettings().setAllowContentAccess(true);
myWebView.getSettings().setDatabaseEnabled(true);
myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.loadUrl(url);
myWebView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
WebView webView = (WebView) v;
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (webView.canGoBack())
webView.goBack();
break;
}
}
return false;
}
});
notificationsButtonClicked();
newNotificationButtonClicked();
calendarButtonClicked();
final PushNotifications pn = new PushNotifications(this);
if (pn.getToken() == null || pn.isExpired()) {
pn.refreshToken("http://www.paotiptipon.co.il/pnfw/register/",
"35299935473");
}
// Bundle extras = getIntent().getExtras();
// if (extras != null) {
// int id = extras.getInt(PushNotifications.ID);
// String title = extras.getString(PushNotifications.TITLE);
// System.out.println(id + title);
// }
}
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mIntentReceiver.abortBroadcast();
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle("×תר×× ××ש×!");
alertDialog.setMessage("×ש ×תר×× ×××©× ××ר×× ××תר××ת! ×××¦× ×¢× ××ש×ר ××× ×ר××ת ××ת×!");
// Setting OK Button
alertDialog.setPositiveButton("××ש×ר",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String url = "http://www.paotiptipon.co.il/%d7%9b%d7%a0%d7%99%d7%a1%d7%aa-%d7%94%d7%95%d7%a8%d7%99%d7%9d-2/%d7%a4%d7%95%d7%a1%d7%98%d7%99%d7%9d/";
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.loadUrl(url);
}
});
// Setting CANCEL Button
alertDialog.setNegativeButton("×××××",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
alertDialog.show();
}
};
private void notificationsButtonClicked() {
Button notifications = (Button) findViewById(R.id.notifications);
notifications.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "http://www.paotiptipon.co.il/%d7%9b%d7%a0%d7%99%d7%a1%d7%aa-%d7%94%d7%95%d7%a8%d7%99%d7%9d-2/%d7%a4%d7%95%d7%a1%d7%98%d7%99%d7%9d/";
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.loadUrl(url);
}
});
}
private void newNotificationButtonClicked() {
Button newNotification = (Button) findViewById(R.id.newNotification);
newNotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "http://www.paotiptipon.co.il/wp-admin/post-new.php";
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.loadUrl(url);
}
});
}
private void calendarButtonClicked() {
Button calendar = (Button) findViewById(R.id.calendar);
calendar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "http://www.paotiptipon.co.il/events/";
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.loadUrl(url);
}
});
}
@Override
protected void onResume() {
super.onResume();
registerReceiver(mIntentReceiver, PushNotifications.getIntentFilter(this));
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(mIntentReceiver);
}
}
first of all thanks for those of you who tried to help.
I found an answer to my question, and I would like to share it here so if anyone needs this it will be here.
I used this link:
Playing HTML5 video on fullscreen in android webview
I just downloaded the example project from there and implemented the code there in my project. The man who wrote those classes is awesome and wrote a really good tutorial on this and it fixed my problem. 🙂