5,600,483 Members 32,778 Now Online
XDA Developers Android and Mobile Development Forum

Block ads on your Android phone (2010-04-15)

Tip us?
 
phaelox
Old
(Last edited by phaelox; 15th April 2010 at 11:01 PM.)
#1  
Senior Member - OP
Thanks Meter 12
Posts: 107
Join Date: Feb 2009
Default Block ads on your Android phone (2010-04-15)

AdFree is a fantastic program created by XDA user delta_foxtrot2 (see this thread in the G1 forum) to facilitate using your hosts file to block ad servers. This makes it extremely easy. Of course you will need root access!


Unfortunately I found some ads still weren't blocked and the last update to the AdFree hosts file happened 2010-02-27. So I decided to update the hosts file myself. I merged the hosts files from adfree/mvps/yoyo and added a bunch of mobile ad providers I've found myself. The list is free of duplicates and comments, so as to keep it as small as possible (it still amounts to about 635 kB).

To install this hosts file, you still need root access obviously:
  1. download the zip
  2. unpack it to the directory where adb.exe is located (if you don't know what adb is or how to get it running, please use the search)
  3. open a command prompt
Code:
adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system 
adb push hosts.for.mobile.txt /etc/hosts
adb shell mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system
You might need to restart your phone. Also clearing the Android browser cache will apparently help in getting rid of already cached ads (worked for me, ymmv).


As for ethical discussions on blocking ads for free apps, blah. I don't so much have a problem with ads, as I do with the personal data that gets send to the ad providers. I'm talking about location data and whatever else they might want to know about my device and what I'm running ("analytics" is a fancy name for "we want to find out as much about you as we possibly can get away with").

Anyway.. use it, don't use it, up to you.

Last updated

15-4-2010 23:23 (20808 hosts blocked)


.
Attached Files
File Type: zip hosts-file-for-android_2010-04-15.zip - [Click for QR Code] (129.1 KB, 19529 views)
[DEVICE] HTC Hero (Kimera 2.1[OC_non-BFS] w/ Sense)
[RADIO] 63.18.55.06PU_6.35.15.11
[RECOVERY] Amon-RA-hero-v1.6.2-blue
[BOOTSCREEN] Android Supernova for Hero
[HOW TO] Make your own bootscreen and create signed zip
[HOW TO] Block ads on your Android phone (2010-04-15)
The Following 8 Users Say Thank You to phaelox For This Useful Post: [ Click to Expand ]
 
loblaw
Old
#2  
loblaw's Avatar
Member
Thanks Meter 3
Posts: 47
Join Date: Apr 2010
Thanks a bunch!
 
Neejay
Old
#3  
Senior Member
Thanks Meter 46
Posts: 703
Join Date: Jul 2009
Location: Atlanta, GA
Thanks for the updated hosts. So should we even bother with the program, especially if it doesn't get updated hardly at all?
- Nexus 5
- Samsung Galaxy Nexus (Maguro)
- HP TouchPad

Code:
nandroid; mess with stuff; (restore || live_with_it)
 
phaelox
Old
#4  
Senior Member - OP
Thanks Meter 12
Posts: 107
Join Date: Feb 2009
Default Re: Block ads on your Android phone (2010-04-15)

You're welcome!

If you push my hosts file, you don't need the AdFree app, but I wanted to acknowledge his work and give people a simpler alternative to using adb.

Best choice right now is my hosts file as it's simply more comprehensive.

Sent from my HTC Hero using the XDA mobile application powered by Tapatalk
[DEVICE] HTC Hero (Kimera 2.1[OC_non-BFS] w/ Sense)
[RADIO] 63.18.55.06PU_6.35.15.11
[RECOVERY] Amon-RA-hero-v1.6.2-blue
[BOOTSCREEN] Android Supernova for Hero
[HOW TO] Make your own bootscreen and create signed zip
[HOW TO] Block ads on your Android phone (2010-04-15)
 
Neejay
Old
#5  
Senior Member
Thanks Meter 46
Posts: 703
Join Date: Jul 2009
Location: Atlanta, GA
Quote:
Originally Posted by phaelox View Post
You're welcome!

If you push my hosts file, you don't need the AdFree app, but I wanted to acknowledge his work and give people a simpler alternative to using adb.

Best choice right now is my hosts file as it's simply more comprehensive.

Sent from my HTC Hero using the XDA mobile application powered by Tapatalk
Understood. Yeah, it was a great start/beginning to blocking ads, but no updates. Thanks again.
- Nexus 5
- Samsung Galaxy Nexus (Maguro)
- HP TouchPad

Code:
nandroid; mess with stuff; (restore || live_with_it)
 
tmayne
Old
#6  
Junior Member
Thanks Meter 0
Posts: 8
Join Date: Apr 2010
Thanks! I've been looking for something like this for awhile. Real quick question: is getting "Data connectivity errors" in browser normal with this? It didn't start till I pushed this on my phone.
 
phaelox
Old
(Last edited by phaelox; 18th April 2010 at 07:03 PM.)
#7  
Senior Member - OP
Thanks Meter 12
Posts: 107
Join Date: Feb 2009
Quote:
Originally Posted by tmayne View Post
Real quick question: is getting "Data connectivity errors" in browser normal with this? It didn't start till I pushed this on my phone.

Short answer: Yes.

Long answer:
You may know this, but I'll explain anyway. The way this works is as follows. The loopback address for any network interface is 127.0.0.1 -- this is the address for the device, but only from the device itself, it loops back on itself. We don't want to waste bandwidth with ads, or have ad providers collect all sorts of data on us, so we don't want to connect to them. Any FQDN -Fully Qualified Domain Name- (for example: analytics.admob.com) needs to be converted into an IP address to be able to connect to it. Here's where the 'hosts' file comes in. It's a simple text file with a record on each line that says redirect 'hostname' to 'ip-address'. So we put a line in that reads '127.0.0.1 analytics.admob.com'. This tells our device that any connection made to 'analytics.admob.com' needs to be redirected to '127.0.0.1', which is your device. Basically a dead-end, as you are not running their webserver serving ads on your device, so this results in a data connection error.

Now, usually you will surf to a site that loads images (advertisements) from a server that is listed in this hosts file, and as a result the ads will not load. That shouldn't popup any error windows. But if you try to visit http://analytics.admob.com in your browser, then yes, you will see an error.

If the latter happens with a site you do wish to visit, just open the hosts file in a text editor (one that supports UNIX-style line ends) and remove the line in question, or put a '#' in front of the line to comment it out.

Hope that made it clearer.
[DEVICE] HTC Hero (Kimera 2.1[OC_non-BFS] w/ Sense)
[RADIO] 63.18.55.06PU_6.35.15.11
[RECOVERY] Amon-RA-hero-v1.6.2-blue
[BOOTSCREEN] Android Supernova for Hero
[HOW TO] Make your own bootscreen and create signed zip
[HOW TO] Block ads on your Android phone (2010-04-15)
The Following User Says Thank You to phaelox For This Useful Post: [ Click to Expand ]
 
tmayne
Old
#8  
Junior Member
Thanks Meter 0
Posts: 8
Join Date: Apr 2010
Yeah it did. No worries though since it seems that after pressing "Ok" everything works fine! Small trade off for blocked ads! Thanks!
 
carbonyle
Old
#9  
carbonyle's Avatar
Member
Thanks Meter 0
Posts: 80
Join Date: Aug 2007
Thanks for this How-TO!

So basicaly that mean we can restrict acces to certain websites from our phone?
eg: adding this line
Code:
127.0.0.1 forum.xda-developers.com
and I'll no longer be able to browse XDA from my phone?

Keep writing such How-To, like this one and the one to sign update.zip, I found this interessant and usefull
 
phaelox
Old
#10  
Senior Member - OP
Thanks Meter 12
Posts: 107
Join Date: Feb 2009
Quote:
Originally Posted by tmayne View Post
Yeah it did. No worries though since it seems that after pressing "Ok" everything works fine! Small trade off for blocked ads! Thanks!
You're welcome, glad I could help.

Quote:
Originally Posted by carbonyle View Post
Thanks for this How-TO!

So basicaly that mean we can restrict acces to certain websites from our phone?
eg: adding this line
Code:
127.0.0.1 forum.xda-developers.com
and I'll no longer be able to browse XDA from my phone?

Keep writing such How-To, like this one and the one to sign update.zip, I found this interessant and usefull
Cheers. And yes, that's exactly right. Just remember the hosts file takes FQDN's, so you can block a domain (or subdomain) this way, but not a directory or page on a domain. Also, blocking a domain does not also block its subdomains.

PS. this method of using the hosts file is not unique to your android phone, it works on most operating systems on PC as well. See this Wikipedia entry for more info.
[DEVICE] HTC Hero (Kimera 2.1[OC_non-BFS] w/ Sense)
[RADIO] 63.18.55.06PU_6.35.15.11
[RECOVERY] Amon-RA-hero-v1.6.2-blue
[BOOTSCREEN] Android Supernova for Hero
[HOW TO] Make your own bootscreen and create signed zip
[HOW TO] Block ads on your Android phone (2010-04-15)

Tags
hosts block filter ads
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes