Android Question retiving chrome browser history (java to b4a)

Devv

Active Member
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
        Dim MassivePrivacyViolation() As String = GetChromeHistory
    For i = 0 To MassivePrivacyViolation.Length-1
        Log(i & ": " & MassivePrivacyViolation(i))
    Next

End Sub



'This will return an array of Strings of the form "title:url:date"
Public Sub GetChromeHistory As String()
  Dim jo As JavaObject
'  jo = Me 'use from within a class
  jo.InitializeContext 'use from within an activity
  Return jo.RunMethod("GetChromeHistoryJava", Null)
 
 

End Sub

#If JAVA
import android.provider.Browser;
import android.net.Uri;
import android.database.Cursor;
import anywheresoftware.b4a.objects.collections.List;

public String[] GetChromeHistoryJava()
{
String[] proj = new String[]{Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL, Browser.BookmarkColumns.DATE };   //NEW
Uri uriCustom = Uri.parse("content://com.android.chrome.browser/bookmarks");
String sel = Browser.BookmarkColumns.BOOKMARK +" = 0"; // 0 = history, 1 = bookmark
Cursor mCur = getContentResolver().query(uriCustom, proj, sel,null,null);
mCur.moveToFirst();

@SuppressWarnings("unused")
String title ="";
@SuppressWarnings("unused")
String url ="";
@SuppressWarnings("unused")  //NEW
String date ="";                      //NEW
List res = new List();
res.Initialize();

if(mCur.moveToFirst()&& mCur.getCount()>0)
{
   boolean cont = true;
   while(mCur.isAfterLast()==false&& cont)
   {
      title = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.TITLE));
      url = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.URL));
      date = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.DATE));      //NEW

      res.Add(title + ":" + url + ":" + date);      //NEW
      mCur.moveToNext();
   }
}
mCur.close();
String[] resArr = new String[res.getSize()];
for(int i=0;i<res.getSize();i++)
{
   resArr[i] = (String)res.Get(i);
}
return resArr;
}
#End If


i'm getting this error



any ideas brother ?
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
It works on my device. Did the previous version, without the date, work for you without issue? You still have the edit to the manifest in place, correct?

I added some logging statements. Show me your logs when you run this:
B4X:
#If JAVA
import android.provider.Browser;
import android.net.Uri;
import android.database.Cursor;
import anywheresoftware.b4a.objects.collections.List;

public String[] GetChromeHistoryJava()
{
     BA.Log("0");
     String[] proj = new String[]{Browser.BookmarkColumns.TITLE,Browser.BookmarkColumns.URL, Browser.BookmarkColumns.DATE };
     BA.Log("1");
     Uri uriCustom = Uri.parse("content://com.android.chrome.browser/bookmarks");
     String sel = Browser.BookmarkColumns.BOOKMARK +" = 0"; // 0 = history, 1 = bookmark
     Cursor mCur = getContentResolver().query(uriCustom, proj, sel,null,null);
     @SuppressWarnings("unused")
     String title ="";
     @SuppressWarnings("unused")
     String url ="";
    @SuppressWarnings("unused")
     String date ="";
     List res = new List();
     res.Initialize();

     if(mCur.moveToFirst()&& mCur.getCount()>0)
     {
         boolean cont = true;
         while(mCur.isAfterLast()==false&& cont)
         {
             BA.Log("position: " + mCur.getPosition());
             title = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.TITLE));
             url = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.URL));
            BA.Log("2");
            date = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.DATE));
            BA.Log("3");
             res.Add(title + ":" + url + ":" + date);
             mCur.moveToNext();
          }
     }
    mCur.close();
    String[] resArr = new String[res.getSize()];
    for(int i=0;i<res.getSize();i++)
    {
        resArr[i] = (String)res.Get(i);
    }
     return resArr;
}
#End If
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
sorry bro my fault i forgot to add the manifest permission thank you very very much!

btw: it will return android ticks right ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…