开发者

How to make entries in Android /etc/hosts file to restrict specific websites [duplicate]

开发者 https://www.devze.com 2023-03-16 22:32 出处:网络
This question already has an answer here: Closed 11 years ago. Possible Duplicate: How to restrict Android device to not open some specific site e.g.youtube, facebook
This question already has an answer here: Closed 11 years ago.

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 You开发者_运维知识库Tube 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消