i found this
https://stackoverflow.com/questions...browsing-history-bookmarks-in-our-android-app
how to convert to b4a ?
https://stackoverflow.com/questions...browsing-history-bookmarks-in-our-android-app
how to convert to b4a ?
'This will return a List of Strings of the form "title:url"
Public Sub GetChromeHistory as List
Dim jo as JavaObject
jo = Me
' jo.InitializeContext 'uncomment this and comment above if using in an activity
Return jo.RunMethod("GetChromeHistoryJava", Null)
End Sub
#If JAVA
public anywheresoftware.b4a.objects.collections.List GetChromeHistoryJava()
{
String[] proj = new String[]{Browser.BookmarkColumns.TITLE,Browser.BookmarkColumns.URL };
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 ="";
anywheresoftware.b4a.objects.collections.List res = new anywheresoftware.b4a.objects.collections.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));
// Do something with title and url
res.Add(title + ":" + url);
mCur.moveToNext();
}
}
return res;
}
#End If
B4A version: 5.20
Parsing code. (0.00s)
Compiling code. (0.04s)
Compiling layouts code. (0.00s)
Generating R file. (0.08s)
Compiling debugger engine code. (1.06s)
Compiling generated Java code. Error
B4A line: 35
End Sub
javac 1.8.0_60
src\b4a\example\main.java:393: error: '.class' expected
String[] proj =newString[]{Browser.BookmarkColumns.TITLE,Browser.BookmarkColumns.URL };
^
1 error
There should be a space between "new" and "String[]....". I fixed a few other typos in the Java snippet as well.
B4A version: 5.20
Parsing code. (0.00s)
Compiling code. (0.02s)
Compiling layouts code. (0.00s)
Generating R file. (0.07s)
Compiling generated Java code. Error
javac 1.8.0_60
src\b4a\example\main.java:382: error: not a statement
res.Initialize;
^
1 error
OK i can do all the troubleshooting and logging, could you plz try to fix it ?Initialize should have parentheses after it: Initialize(). And a few other typos.
Like I said before, this is untested code, presented without warranty. I haven't tested it and the original author of the Java snippet on Stack Overflow claims not to have tested it. It's going to take some troubleshooting on your part to get it working if it works at all.
'This will return an array of Strings of the form "title:url"
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 };
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 ="";
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));
// Do something with title and url
res.Add(title + ":" + url);
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
AddPermission("com.android.browser.permission.READ_HISTORY_BOOKMARKS")
(What i'm doing wrong ?)[Ljava.lang.String;@429ae3d0
Sub Activity_Create(FirstTime As Boolean)
Log(GetChromeHistory)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
'This will return an array of Strings of the form "title:url"
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 };
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 ="";
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));
// Do something with title and url
res.Add(title + ":" + url);
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
Dim MassivePrivacyViolation() as String = GetChromeHistory
For i = 0 to MassivePrivacyViolation.Length-1
Log(i & ": " & MassivePrivacyViolation(i))
Next
Read the comments for GetChromeHistory. It returns an array of Strings. You have to iterate through the array:
B4X:Dim MassivePrivacyViolation() as String = GetChromeHistory For j = 0 to MassivePrivacyViolation.Length-1 Log(i & ": " & MassivePrivacyViolation(i)) Next
You should start a new thread for this as it is not related to THIS thread.is getting the stock android browser history possible ?
Use this uri: content://com.android.chrome.browser/bookmarks instead of Browser.BOOKMARKS_URI
You should start a new thread for this as it is not related to THIS thread.
You posted a link to stackoverflow with the state
You realized it now... You need to go the opposite way to get the other history (using Browser.BOOKMARKS_URI) i believe
** Activity (main) Create, isFirst = true **
main_getchromehistory (B4A line: 42)
Return jo.RunMethod("GetChromeHistoryJava", N
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:423)
at b4a.example.main._activity_create(main.java:351)
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:467)
... 21 more
date = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.DATE));
I had no luck to do that, i know nothing about java, can you please write that for me ? i could pay a little over paypal if you are interestedAdd Browser.BookmarkColumns.DATE to the end of the proj array. Then create a String variable date just below where the title and url String variables are created. Then, in the main loop, add:
B4X:date = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.DATE));
Then change the res.Add() line in the loop to include the date String.
'This will return an array of Strings of the form "title:url:date"
Public Sub GetChromeHistory As String()
Dim jo AsJavaObject
' 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