I made an app that shows my Web site that has youtube videos in it. I used this code to play it in full screen: Playing HTML5 video on fullscreen in android webview Now I submitted the app for review and Google rejected it because it can keep playing the videos when you lock the screen. How can I disable this behavior so they approve my app? Thanks in advance!!
-
I'm voting to close this question as off-topic because questions about app stores are off-topic. See meta – Zoe Jan 22 '19 at 16:49
3 Answers
I found this article. The following code shows you if screen is turned off or not
@Override
protected void onCreate() {
// INITIALIZE RECEIVER
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
BroadcastReceiver mReceiver = new ScreenReceiver();
registerReceiver(mReceiver, filter);
// YOUR CODE
}
@Override
protected void onPause() {
// WHEN THE SCREEN IS ABOUT TO TURN OFF
if (ScreenReceiver.wasScreenOn) {
// THIS IS THE CASE WHEN ONPAUSE() IS CALLED BY THE SYSTEM DUE TO A SCREEN STATE CHANGE
System.out.println("SCREEN TURNED OFF");
} else {
// THIS IS WHEN ONPAUSE() IS CALLED WHEN THE SCREEN STATE HAS NOT CHANGED
}
super.onPause();
}
Then you can call webView.onPause();
A second way to solve your problem would be just to override onPause()
method on activity like this:
@Override
public void onPause() {
super.onPause();
webView.onPause();
}
It works for me

- 625
- 5
- 16
-
Thank you very much! The second way you wrote worked fine and Google approved my app :) – Adi Vizgan Jun 05 '16 at 08:41
After some research based on @BooDoo s onPause implementation, I found that not only onPause
exists for the webview, it also has an onResume
method.
So designing your activity that plays a video with these events, it should go ok:
@Override
protected void onPause() {
super.onPause();
webView.onPause();
}
@Override
protected void onResume() {
super.onResume();
webView.onResume();
}
The Resume event lets your video player continue at the same position where you left when you paused it.

- 3,105
- 3
- 25
- 42
override fun onResume() {
super.onResume()
webView.onResume()
}
override fun onDestroy() {
webView.onPause()
super.onDestroy()
}
Hey, I can accept that given answers for onPause are working but I had an issue with it. I have Interstitial ad in my app and calling webView.onPause()
in onPause make the interstitial ad unclickable. (Because activity going on resume and ad losing focus).
I am sharing this for those who have same issue.

- 321
- 6
- 9