Android Browsing history leaving out some sites only
Asked Answered
C

1

24

Using the function below I am trying to get the LAST url that the user visited from Chrome Browser on their Android Phone. This function works very well for most sites, but does not work for "www.reddit.com".

The url variable below updates if I go to "www.google.com", "www.hulu.com" or "www.kayak.com" but will not update if I go to "www.reddit.com".

It does update if I go to "m.reddit.com". Same problem with facebook, detects m.facebook.com but not www.facebook.com.

I don't understand What's the difference between "www.reddit.com" and "m.reddit.com" that Android records one but not the other.

What change do I need in the code to detect ALL URL ACCESSES?

public String returnLastChromeURL(int browserCode) {
    String[] proj = new String[] { Browser.BookmarkColumns.DATE,
            Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL };

    String dateTime;
    Uri uriCustom = Uri
            .parse("content://com.android.chrome.browser/bookmarks");
    String sel = Browser.BookmarkColumns.BOOKMARK + " = 0"; // 0 = history,
                                                            // 1 = bookmark
    try {
    Cursor mCur = mContext.getContentResolver().query(uriCustom, proj, sel,
            null, BookmarkColumns.DATE + " ASC");
    mCur.moveToFirst();
    mCur.moveToLast();

        dateTime = mCur.getString(mCur
                .getColumnIndex(Browser.BookmarkColumns.DATE));
        title = mCur.getString(mCur
                .getColumnIndex(Browser.BookmarkColumns.TITLE));
        url = mCur.getString(mCur
                .getColumnIndex(Browser.BookmarkColumns.URL));

        mCur.close();
    } catch (Exception e) {
        dateTime = String.valueOf(System.currentTimeMillis());
        title = "";
        url = "empty_list";
    }

    return url;
}

Some more info from my debug:

  • When I try this on a Genymotion Emulator, all websites (including sites like www.reddit.com get detected ok). On a real phone www.reddit.com does not get detected.
  • Sites the code will detect OK: www.kayak.com' (redirects towww.kayak.com/mn),www.hulu.com(loads mobile version of site though url stays www.hulu.com),www.google.com` (same story as the hulu).

Seems like that the sites that load the pure desktop version of the site, do not get detected

Camise answered 21/4, 2015 at 15:13 Comment(4)
Have you tried "getAllVisitedUrls" compare with your code? May got some diffrent result? Here are some smaples: anddev.org/other-coding-problems-f5/… and programcreek.com/java-api-examples/… (example 3) Hope I din't give you the wrong way...Cirillo
could it be because of the presence of the tags : <link rel="alternate" media="only screen and (max-width: 640px)" href="https://m.reddit.com/" /> and <link rel="alternate" media="handheld" href="https://m.facebook.com/" /> while it is absent in the other pages that you mentioned ?Distillation
@Distillation - hmmm, good observation but not sure why that would matter. besides even "www.reddit.com" (i.e. desktop version of the site is not getting detected). I tried it on a Genymotion Emulator and all urls (including www.reddit.com) are getting detected, so I am still confused.Camise
@Cirillo - Thanks, will try out to the samples later today.Camise
A
8

This is because you never visit the desktop domain on your mobile , actually each time you visit facebook on your mobile ( or any other website that detects your navigator ) it will automatically redirects you to the mobile website , redirections will not be saved in history unless page loads , which never happens.

Check the following screenshot taken from my true N7100 galaxy note2 and my windows browser :

if you are using chrome browser you can request desktop website ( which is not a reliable solution as user will have to do this manually ).

another solution is to override redirection method which will not work due to XSS policy.

so a better solution is to fake your browser and convince the server that you are using a desktop browser check this answer .

The simulator on desktop uses device user agent which will count as desktop browser. screenshot

Algol answered 29/4, 2015 at 21:6 Comment(9)
Thanks but not sure how the answer can be implemented in Android. Any hint here would help.Camise
@Camise when you go to facebook.com , does your mobile redirect to m.facebook.com ? or are you doing it manually ?Algol
When I type "facebook.com", chrome goes to "www.facebook.com" desktop site. I have to actually type "m.facebook.com" to go to the mobile site.Camise
I have to manually go to m.facebook.com, no auto redirection to the mobile site on going to www.facebook.comCamise
@Camise are you browsing using request desktop site turned on ?Algol
Nope. that setting is not turned on. See here: dropbox.com/s/6cftrlea90twuis/2015-05-11%2003.55.02.png?dl=0Camise
I updated the question (see towards the end) with an observation. Basically, Seems like that the sites that load the pure desktop version of the site, do not get detected. Really would like to find a way around this.Camise
@Camise i think this is a specific issue with your device , because normally when i open any of these sites on my device , i get redirected , are you running a custom rom ? it will be helpful if you send 'about device' screenshot.Algol
@PrllyGeek - Sorry about the late response, I've been trying a few things. Does this behavior look ok to you? I go to "facebook.com" and Chrome does not redirect to mobile site. I do NOT have hte option to Request Desktop site selected: youtube.com/watch?v=5ziiyxhICPQCamise

© 2022 - 2024 — McMap. All rights reserved.