1

Possible Duplicate:
How to restrict Android device to not open some specific site e.g.youtube, facebook

I am developing an application where a feature is to stop users to use YouTube or facebook while they are using the application. By some finding I came to know that I have to edit /etc/hosts .... but how ... thats what I want to know...

some one told me to make entries in this file to restrict specific websites but for that I need root privileges.

2
  • Are you aware that this requires the device to be rooted? Commented Jun 30, 2011 at 11:50
  • If you are using the a rooted device or the emulator, just follow this tutorial: blog.chrisblunt.com/… Commented Apr 19, 2012 at 17:12

2 Answers 2

2

There is no way to edit the /etc/hosts files from application code (code that is installed from the market or on a device that hasn't been rooted).

If the device has been rooted then you could just su and then write new data to it, but on a production device you won't have the necessary permission.

EDIT: what may make more sense (and I don't know how easy/difficult this will be in practice) is to use a custom DNS server that resolves IP addresses you want to ban. If you log in with adb shell you can run getprop which will list all the parameters. Find the DNS parameters and then do setprop {dns parameter name} {new dns ip} where you point to a dns server you control.

Sign up to request clarification or add additional context in comments.

Comments

1

I guess you've heard about something like this, which suggests a way to block ad hosts by setting their IP address to 127.0.0.1 in the hosts file.

The page does say to reboot, but not sure if this is for changes to the file, or rather for when you create the file in the first place. I would guess the latter. Normally changes to /etc/hosts are picked up dynamically.

Whether you can update the hosts file from application code, I have no idea.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.