Obtain browser bookmarks from the database (Android browser Development)

Source: Internet
Author: User

Sometimes the browser's bookmarks may be used. You can use the following code to obtain the information.

Contentresolver = getcontentresolver (); cursor = contentresolver. query (browser. bookmarks_uri, browser. history_projection, whereclause, null, orderby); While string orderby = browser. bookmarkcolumns. visits + "DESC"; string whereclause = browser. bookmarkcolumns. bookmark + "= 1 ";


Orderby refers to the sorting method, and whereclause is the selection condition. In this way, you can obtain the bookmarks of the self-contained browser in Android.

Then, we can define three arraylists to store information obtained from the database.

 listTitle = new ArrayList<String>();        listUrl = new ArrayList<String>();        listBitmap = new ArrayList<Bitmap>();

Traverse cursor and save the information to arraylist:

 while(cursor!=null && cursor.moveToNext()){            listTitle.add(cursor.getString(cursor.getColumnIndex(Browser.BookmarkColumns.TITLE)));            listUrl.add(cursor.getString(cursor.getColumnIndex(Browser.BookmarkColumns.URL)));            byte[] b = cursor.getBlob(cursor.getColumnIndex(Browser.BookmarkColumns.THUMBNAIL));            if(b!=null){                listBitmap.add(BitmapFactory.decodeByteArray(b, 0, b.length));            }else{                listBitmap.add(((BitmapDrawable)(getResources().getDrawable(R.drawable.ic_launcher_browser))).getBitmap());            }        }        

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.