How to block special websites or IPs in Android programmatically?

My application is going to block some websites for children.

Before we start, I should mention that my application is a device administrator application, if helps.

One way of doing this, is to edit /etc/hosts file like on Linux, but on Android, this file is a kernel file, So I can't edit it without root permission.

Second, is to create a local proxy, and check the phone traffic, so I can block special IPs. (Don't know how to do it or if android lets third-party apps to do this?) (Remember that my app is a device administrator application)

Third, is to create a virtual DNS, and there, I can choose which IPs to connect or not. I found an open source app (DNS66) which does the same thing, but don't know how.

Any idea?


You cannot block selected domains without access to network level which required from you to write lower level code(C language), DNS66 only intercept DNS requests which will allow you to block in some cases but nothing more.

If you write code using NDK you will be able to achieve that.