App rejected because YouTube videos can play when screen is off

独自空忆成欢 提交于 2019-12-23 05:02:17

问题


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!!


回答1:


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




回答2:


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:


override fun onResume() {
    super.onResume()
    webView.onResume()
}


override fun onDestroy() {
    super.onDestroy()
    webView.onPause()
}

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.



来源:https://stackoverflow.com/questions/37520372/app-rejected-because-youtube-videos-can-play-when-screen-is-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!