Android web monitor development

I would like to track / filter the websites that the user opens in Android.

I know how to get the last visited URL (in the default Android browser) using ContentObserver in the browser history ...

private static class BrowserObserver extends ContentObserver { private static String lastVisitedURL = ""; private static String lastVisitedWebsite = ""; //Query values: final String[] projection = new String[] { Browser.BookmarkColumns.URL }; // URLs final String selection = Browser.BookmarkColumns.BOOKMARK + " = 0"; // history item final String sortOrder = Browser.BookmarkColumns.DATE; // the date the item was last visited public BrowserObserver(Handler handler) { super(handler); } @Override public void onChange(boolean selfChange) { onChange(selfChange, null); } @Override public void onChange(boolean selfChange, Uri uri) { super.onChange(selfChange); //Retrieve all the visited URLs: final Cursor cursor = getContentResolver().query(Browser.BOOKMARKS_URI, projection, selection, null, sortOrder); //Retrieve the last URL: cursor.moveToLast(); final String url = cursor.getString(cursor.getColumnIndex(projection[0])); //Close the cursor: cursor.close(); if ( !url.equals(lastVisitedURL) ) { // to avoid information retrieval and/or refreshing... lastVisitedURL = url; //Debug: Log.d(TAG, "URL Visited: " + url + "\n"); } } } 

To register ContentObserver I use:

 browserObserver = new BrowserObserver(new Handler()); getContentResolver().registerContentObserver(Browser.BOOKMARKS_URI, true, browserObserver); 

And unregister:

 getContentResolver().unregisterContentObserver(browserObserver); 

It works. However, I can only parse URLs after the browser has downloaded them.

Now, is there a way to get the URLs before the browser loads them on Android?

+4
source share
1 answer

A solution that can help create a web monitor is to create your own VPN service so that you can monitor all device traffic. A good example of this is the NetGuard project.

https://github.com/M66B/NetGuard

Please note that in some devices the system will not pass certain applications through the VPN (for example, on Samsung devices, the Samsung web browser is not sent through the system VPN, it is tested on S5 with Android 6.0).

Your application should also request permission to use as a VPN service, but as soon as the user grants this permission, he will be able to control and filter most of the device’s network traffic.

+1
source

Source: https://habr.com/ru/post/1489033/


All Articles