URL History Log

misu

New Member
Licensed User
Longtime User
This is my very first post... in a long series, I hope. Hello B4A developers!

I would like to track the internet activity on the phone, so I am trying to get a log of the visited urls. I know it can be done, but I don't know how. I've searched the forums and all I found out was that the app needs to get the READ_HISTORY_BOOKMARKS permission in order to access the url history. This permission can be obtained by setting it in the AndroidManifest.xml file - I get this. But how do I exactly get the list of the visited urls programatically with b4a?

Any hints much appreciated, then once I figure this out I promise to post it as a tutorial for others to use, since I didn't find anything on this subject.

Thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code:
B4X:
Sub ReadHistory
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod("getContentResolver")
   Dim cr As Cursor = r.RunStaticMethod("android.provider.Browser", "getAllVisitedUrls", Array As Object(r.Target), _
      Array As String("android.content.ContentResolver"))
   For i = 0 To cr.RowCount - 1
      cr.Position = i
      Log(cr.GetString2(0))
   Next
End Sub

It requires Reflection and SQL library.
You should add this line to the manifest editor:
B4X:
AddPermission(com.android.browser.permission.READ_HISTORY_BOOKMARKS)
 
Upvote 0

misu

New Member
Licensed User
Longtime User
Awesome! Thanks, Erel... I'm pretty new to the forum, but from what I've browsed, I noticed you made sure no thread is left without at least a reply... and pretty much everybody get their answers!

I'm thinking to upgrade now to the newest b4a version...
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Awesome! Thanks, Erel... I'm pretty new to the forum, but from what I've browsed, I noticed you made sure no thread is left without at least a reply... and pretty much everybody get their answers!

Erel is a machine, not a human.. See here (Posts #22-#25) :D

b4arulez.gif
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
You can create your own file with URL, Date and Time written for each visit.

B4X:
Sub Globals
    Dim WebView1 As WebView
    WebView1.Initialize("WebView1")
    Dim VisitedWebs As List
    VisitedWebs.Initialize
End Sub
 
Sub WebView1_OverrideUrl(Url As String) As Boolean
    VisitedWebs.Add(Url & "-" & DateTime.Now)
    File.WriteList(File.DirInternal, "visitedwebs.txt", VisitedWebs)
    Return False
End Sub
 
Upvote 0

jefflynn1974

Member
Licensed User
Longtime User
I think your code is not exactly that I need. I think your code (correct me if I am wrong) is listening the actual web visits when the application is running. But this is not good for me because my app is running periodically and try to get the visited URLs from the stored datas. So Erel's code is better in my case just I would like to get the history's date too if it is possible.
 
Upvote 0
Top