0

I put Admob ad on webView connecting the blog. Most of the contents are text. But some have youtube videos. Play Store rejects my app because there is an Admob app when youtube video is playing. Is there any way to hide AdMob ad when youtube video is playing on webView?

cloud
  • 77
  • 6
  • 1
    https://stackoverflow.com/questions/55406469/how-to-check-if-webview-youtube-video-player-was-started – Usama Altaf Jan 06 '21 at 13:08
  • @UsamaAltaf Thank you for the link. But actually, I cannot understand how to use it with Java language. – cloud Jan 06 '21 at 13:17
  • Read this: https://stackoverflow.com/questions/4549401/correctly-disable-admob-ads – maxmitz Jan 06 '21 at 13:18
  • @Theodeo Thank you. So maybe it's possible to disable AdMob when the only youtube play? I searched a lot but it seems there is no exact example code for it. As a beginner, it is difficult to code with other kinds of examples. – cloud Jan 06 '21 at 13:34
  • @cloud: How did you solved the problem? – Bishwash Apr 15 '21 at 13:54

1 Answers1

0

You can do something like this with some practise.

private WebResourceResponse getImageWebResource(InputStream data) {
        return new WebResourceResponse("image/jpg", "UTF-8", data);
    }

    @Nullable
    @Override
    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
        if(url.contains("youtube")){
            
    }
        return super.shouldInterceptRequest(view, url);
    }

you can use some picture for ads in the if(url.contains("youtube")) method

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.picture_to_load);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);return getImageWebResource(bis);    
Usama Altaf
  • 1,036
  • 1
  • 4
  • 23
  • Thank you for your answer. As I understand that your code is to stop youtube playing, right? I am looking for stopping Admob ad when youtube play. So I think it's different that I am looking for. – cloud Jan 09 '21 at 03:41