How to retrieve and display browser history and bookmarks in browser application [duplicate]

微笑、不失礼 提交于 2020-01-14 03:11:07

问题


Hi friends i am new to android I don't know how to retrieve and display history in web browser.

Please guide me and share your thoughts, ideas and bookmarks too.

I have to display history in ListView


回答1:


ArrayList mTitles=new ArrayList();
ArrayList mUrls=new ArrayList();



 public void getBrowserHist()  {
            Cursor mCur = 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();
               }
          }
    }

Add below uses-permission into your manifest file.

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

Enjoy :-)




回答2:


You can use getContentResolver to get the browser history as managedQuery has been depricated.

String[] proj = new String[] { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL };
String sel = Browser.BookmarkColumns.BOOKMARK + " = 0"; // 0 = history, 1 = bookmark
Cursor mCur = getContentResolver().query(Browser.BOOKMARKS_URI, proj, sel, null, null);
mCur.moveToFirst();
String title = "";
String url = "";
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
        mCur.moveToNext();
    }
}

Also add permissions in your manifest

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

For more details to access data using Cursor check Access Data using Cursor



来源:https://stackoverflow.com/questions/24277592/how-to-retrieve-and-display-browser-history-and-bookmarks-in-browser-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!