views:

966

answers:

3

I want to read browser history in Android phone.

I have done some document reading, then I come to know that we can read browser history by android.provider.Browser class. It has :

final static Cursor
getAllVisitedUrls(ContentResolver cr)

...method which returns Cursor.

May I get help to handle Cursor, or any example code to get browser history?

+2  A: 

Not really an answer but I can tell you what I did.

I first clone the browser repo and try to reproduce how they get the history. And I started getting:

Permission Denial: reading com.android.browser.BrowserProvider

So I added:

<uses-permission android:name="android.permission.READ_HISTORY_BOOKMARKS" />

But it still is giving me the same error. I google it and I found this web.

Hope it helps.

Macarse
Set True to Unknown sources in Application settings on device to install application may be this will solve permission problem
Mitul Nakum
A: 

I am abele to get history from following code

Cursor mCur = activity.managedQuery(Browser.BOOKMARKS_URI,
                    Browser.HISTORY_PROJECTION, null, null, null);
            mCur.moveToFirst();
            if (mCur.moveToFirst() && mCur.getCount() > 0) {
                while (mCur.isAfterLast() == false) {
                    Log.v("titleIdx", mCur
                            .getString(Browser.HISTORY_PROJECTION_TITLE_INDEX));
                    Log.v("urlIdx", mCur
                            .getString(Browser.HISTORY_PROJECTION_URL_INDEX));
                    mCur.moveToNext();
                }
            }
Mitul Nakum
A: 

thanks for your help with bookmark but can you tell me how i can read all history? i managed all permissions and Cursor mCursor = Browser.getAllVisitedUrls(getContentResolver()); mCursor.moveToFirst();

    int rowCount = mCursor.getCount();

    Log.v("Count websites: ", ""+rowCount);

    for(int i=0; i<rowCount;i++)
    {

        Log.v("websites: "+i, ""+mCursor.getString(Browser.HISTORY_PROJECTION_VISITS_INDEX));
        Log.v("websites: "+i, ""+mCursor.getString(Browser.HISTORY_PROJECTION_URL_INDEX));

        if(!mCursor.isLast())
        {
            mCursor.moveToNext();
        }
    }

whats wrong with my code? please if you know then reply me

SAM
not sure but how can you be sure that your cursor (mCursor) is on first record?so it should moved to first record with mCursor.moveToFirst()
Mitul Nakum