Android Question samsung sbrowser url history

Steveb

Member
Licensed User
Longtime User
I am developing for a Samsung Note 4 using Lollypop 5.1.1 and it is using the sbrowser instead of the native android browser. For some reason (still investigating) the URL history is empty so cannot get this crucial information.

I have found this thread on the samsung website:

http://developer.samsung.com/forum/...rdName=General&messageId=253311&startId=zzzzz

Can anyone please help me put this into b4a code or point me in the right location. I am using version 3.84 of the compiler, will an upgrade help me to the latest version?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Steveb

Member
Licensed User
Longtime User
Been trying to solve this using content resolvers and feeling really silly as cannot get any working.

The line in provided code to link to the normal non samsung browser:

Dim cr As Cursor = r.RunStaticMethod("android.provider.Browser", "getAllVisitedUrls", Array As Object(r.Target), _
Array As String("android.content.ContentResolver"))


obviously needs replacing, I have tried all the differences I can think of, ie:

Dim cr As Cursor = r.RunStaticMethod("android.app.sbrowser", "history", Array As Object(r.Target), _
Array As String("android.content.ContentResolver"))


and the b4a application crashes every time at this line. I have tried replacing android.app.sbrowser with all manner of strings ie com.sec.android.app.sbrowser, android.provider.sbrowser from the samsung help page and sure its something I have not totally understood about contentresolvers but still cannot get it working.
 
Upvote 0

Steveb

Member
Licensed User
Longtime User
Thanks Erel, nearly there I think, now I have got rid of the reflector and looked at the contentresolver more fully (as in your first post).

I would not bother you as sure I can solve it but time is running out for me to get this working...so here is the code and the error:

LastException = java.lang.RuntimeException: Object should first be initialized (Cursor).

B4X:
Try
           
        Dim u As Uri
        Dim cr As ContentResolver
        cr.Initialize("cr")
        u.Parse("content://com.sec.android.app.sbrowser/history")
               
        Dim curs As Cursor = cr.Query(u, Null, Null, Null, Null)

    Catch
        SQLStuff.WriteLogs("ContentResolver Attempt = " & LastException.Message)
       
   
    End Try
 
   Try
  
   If curs.RowCount > 0 Then
     curs.Position = curs.RowCount - 1
        
        LastURL = curs.GetString2(0)
    
    
    
     SQLStuff.WriteLogs("LastURL = " & LastURL)
    
        
    Else
    LastURL = "Browser History Empty"
   
    End If
   
    Catch
        SQLStuff.WriteLogs("Browsing Cursor for last record = " & LastException.Message)
   
    End Try
Not wanting to give up will continue getting this working as really hate admitting defeat.
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Welcome @Steveb .. Try to use code tags when posting code ... much easier to read.
[code]paste/insert code here[/code]
 
Upvote 0

Steveb

Member
Licensed User
Longtime User
Edited, sorry, its the second part of the code that is the problem ie navigating through the curs cursor if you have not already guessed.
 
Upvote 0

Steveb

Member
Licensed User
Longtime User
Yes and have finally sorted it. To help other stuck on the same thing, here is the code:

B4X:
Try
           
        Dim u As Uri
        Dim crt As ContentResolver
        crt.Initialize("crt")
        Dim curs As Cursor
        Dim TURL As String
       
        u.Parse("content://com.sec.android.app.sbrowser.browser/history")
               
        curs = crt.Query(u, Null, "", Null, "")

    Catch
        SQLStuff.WriteLogs("ContentResolver Attempt = " & LastException.Message)
       
   
    End Try
  
   Try
   'SQLStuff.WriteLogs("Number of curs records = " & curs.RowCount)
   
   If curs.RowCount > 0 Then
     
     
     curs.Position = curs.RowCount - 1
        
        TURL = curs.GetString("URL")
       
       
        If LastSURL <> TURL Then
            LastSURL = curs.GetString("URL")
            SQLStuff.ExecuteSQL("Samsung Sbrowser","URL Visited",LastSURL, "Browser")
            SQLStuff.WriteLogs("SBrowser latest record = " & LastSURL)
        End If
       
     
     
     'SQLStuff.WriteLogs("LastURL = " & LastSURL)
     
         
    Else
    LastSURL = "Browser History Empty"
   
    End If
   
    Catch
        SQLStuff.WriteLogs("Browsing Cursor for last record = " & LastException.Message)
   
    End Try

Obviously ignore my SQLStuff calls, LastSURL gets the last URL added to the history. Thanks Erel for the help and pointers, why samsung have to make things so different is beyond me.
 
Upvote 0
Top