Android Question retiving chrome browser history (java to b4a)

Devv

Active Member
Licensed 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

** Activity (main) Create, isFirst = true **
main_getchromehistory (B4A line: 49)
Return jo.RunMethod("GetChromeHistoryJava", Null
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at b4a.example.main._getchromehistory(main.java:421)
at b4a.example.main._activity_create(main.java:349)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at b4a.example.main.afterFirstLayout(main.java:106)
at b4a.example.main.access$000(main.java:21)
at b4a.example.main$WaitForLayout.run(main.java:84)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at b4a.example.main.GetChromeHistoryJava(main.java:464)
... 21 more
job failure:101


any ideas brother ?
 
Upvote 0

Roycefer

Well-Known Member
Licensed 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
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
Top