Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

java - How to hide admob ad when youtube video plays on webView?

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...