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

Search This thread

TheWall279

Member
Nov 10, 2009
8
8
Atlanta
Sorry but this needs to be done. Your stealing from the developers. Put this in your application to view the hosts file and see if they are blocking the ads.

BufferedReader in = null;
Boolean result = true;
try {
in = new BufferedReader(new InputStreamReader(new FileInputStream("/etc/hosts")));
String line;
while ((line = in.readLine()) != null)
{
if (line.contains("admob")) // change this to whichever site you use
{
result = false;
break;
}
}
} catch(Exception e){}
if(result == false){
Toast.makeText(getApplicationContext(),"admob detected in /etc/hosts", Toast.LENGTH_LONG).show();
adBlockerFound();
}
public void adblockerFound(){
/**
Do all the bad stuff here. I usually use a dialog and simply notify the user but I still let them use the application. I pretty much give them a guilt trip. But if you wanna be nasty you can do this.finish();

Ive also seen people ask for SU and then make the hosts file writeable and edit the admob out during the readline()
**/
}
 

Top Liked Posts

  • There are no posts matching your filters.
  • 8
    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)


    .
    5
    Hello, since this is the top search result for this topic on Google I'd thought I'd share an update. This is a simple method:

    1. Boot into clockworkmod recovery
    2. partitions > mount /system
    3. adb push hosts /system/etc/hosts
    4. adb reboot

    No need to play with remount and permissions in recovery. Working on CM7 RC2 on HTC Aria. I have updated the hosts file using the sources in the comments as of March 8, 2011.

    Edit: Put mobile advertisers from original list back in and removed duplicates.
    2
    I've shamelessly stolen from the hosts files in this thread and then added my own to make an up-to-date list that mainly works for me.

    The file is sorted, (with the exception of the localhost entry), with duplicates removed.
    2
    caps are important - yes, however, it is strange that the hosts file is HOSTS on your Android ROM... but I guess nothing is impossible...

    @No-Frost: If you have Terminal Emulator and some Superuser app for granting root privileges, you can use the following:

    You need to place the hosts file on your SD card to begin with (in this example, the hosts file is: /mnt/sdcard/hosts.final)

    Next, you need to mount the filesystem in read-write mode, as it is read-only by default

    su
    mount -o remount,rw /dev/block/mtdblock3 /system
    mv /etc/hosts /etc/hosts.bak
    cp /mnt/sdcard/hosts.final /etc/hosts
    chmod 644 /etc/hosts
    mount -o remount,ro /dev/block/mtdblock3 /system
    ls -l /etc/hosts


    That should move the hosts.final file from the root of your SD card, into the /etc directory, and apply the filename: hosts

    Be weary of filenames and foldernames under linux - they are case-sensitive... you don't want System or ETC, etc.

    Once you've executed the last line in the script ls -l /etc/hosts, you should be able to verify that the hosts file exists, with the correct access rights.

    Maybe reboot at this point.

    Quit Terminal Emulator, open your browser, maybe clear the cache in the browser, and open one of the ad-servers listed in your hosts file, e.g.:
    http://00fun.com
    If the page fails to load, then everything worked!

    If you still get ads in apps or websites after the above test succeeded, then it could be that the specific app or website is sourcing it's ads from another host that is not yet in the hosts file, or via some other means...
    2
    Finally got it to work.

    Now there is no way I got this working from terminal app, adb + phone booted or default recovery mode (traingle screen). However if you boot into clockwork recovery mode, manually mount system and sdcard and than use the commands from this topic it will work.