how to capture url opened in android mobile browser
my requirement capture opend urls and maintain in list view
Thanks in advance
aSwan
after playing with some other apps that appear to be doing this very thing, I think this is roughly how they are doing it:
- create a background application that monitors running procs (check frequently, like every .2 seconds or something like that)
- if the browser is running, then request the current browser history list (this requires the com.android.browser.permission.READ_HISTORY_BOOKMARKS permission).
- If, for example, you are looking for malicious/offensive urls, then kill the browser immediately if you find anything in the history list and remove those offensive urls from the history (this requires the com.android.browser.permission.WRITE_HISTORY_BOOKMARKS and android.permission.KILL_BACKGROUND_PROCESSES permissions)
- If you did kill the browser, it will get restarted the next time the user selects the browser button/icon.
It's fairly inelegant, but I think it's the only way to do this right now. It also only works for the built-in browser (you'd have to specifically arrange to monitor other browser processes and histories if you wanted to work for them as well.)
This is essentially not possible with the stock browser on an android consumer device for security and privacy reasons.
You may be able to use netstat (or look in /proc/net/tcp) to see the IP addresses and port numbers of currently active connections, but this won't tell you the file being accessed or even in many cases the specific site as mapping between IP and host names is not 1:1. And it might happen when you aren't looking.
On a rooted phone you can extract the browser's history database.
You can write your own browser leveraging the same underlying webkit engine, or even the stock browsers sources, while also providing some kind of monitoring or history api. But the user has to decide to use that instead of the stock browser.
精彩评论