Online Storage or Online Backup: What's The Difference?.Time Machine vs Arq vs Duplicati vs Cloudberry Backup.Here we load directly into a static Set variable, which would persist in memory as long as the app process runs, but let’s keep it simple here. One thing to keep in mind is we should do I/O operation in background thread. Okio is used below, but it can be replaced by java.io APIs. In either case we will have to do I/O operation to read from this file. We can either save this list to a file, include it as an asset, or as a raw resource in our app 3. Since we only care about hostnames without IP addresses, let’s choose plain non-HTML list - as a plain list of hostnames (no HTML) with no links back to this page (we should accredit it somewhere else of course). site provides a few options to generate the list. Check if the request URL belongs to one of the hostnames in the list and override it, returning a dummy resource instead of the actual one, which is supposed to be ads.Use WebViewClient.shouldInterceptRequest(WebView, String) to intercept requests.Save the list somewhere, load it when application starts.Now we only need to match blacklisted hostnames with our URL! list 2 used by uBlock Origin seems to be promising though: it generates all hostnames considered ad servers. Easylist, EasyPrivacy, etc are some well known ones, but are overkill for our needs: they specify sites with CSS selectors, while we only have a URL to work with here. Now how do we identify if resources from a URL are potentially ads? Let’s check how popular ad blockers like uBlock Origin or AdBlock do it: they both have a few black lists of things to filter. We can use shouldInterceptRequest() to intercept each request issued by a webpage, check its URL and decide whether we want to load resources from that URL. A little digging into WebView documentation leads us to WebViewClient 1. We’re gonna need to prevent WebView from loading ads, or unwanted resources, when it tries to load a webpage. I was shuffling to catch up with news waiting for Google I/O 2016 to start (which was 1AM my timezone), while an idea just popped up: let’s build an ad blocker to browse news in my phone without the unwanted distraction!
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |