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);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…