Thursday, November 14, 2013

Browser History and bookmarks

In this post, you will learn to create a simple Android app to view browser history and bookmarks. This app displays the browser history and bookmarks in a single list. It can also be used to clear the browser history from your Android device. In addition, the user is able to click a link on the list to open the page on the browser.
To develop this app, you will need to create an Android project in Eclipse. The name of the project or application will be BClean. The BClean app has the simple user interface. When the app firstly launches, it displays a list of browser history and bookmarks. You will need to edit the activity_main.xml file to include a ListView component. Here is the content of the activity_main.xml file.

activity_main.xml file

<RelativeLayout xmlns:android=""
    tools:context=".MainActivity" >



Each item of the list will display three fields of each browser history or bookmark. The first field is the icon. The second field is the title and the third field is the url.

browser history and bookmarks view and clean

To customize the ListView component to allow each row or item to show the data in that way, you will need the listlayout.xml and files. The listyout.xml file represents the layout of each row or item of the list. There are three components in the listlayout file. The first component is an ImageView. It is for displaying the icon. The second and third components are TextView compoennts for displaying the title and url.

listlayout.xml file

<?xml version="1.0" encoding="utf-8"?>
<!--  Single List Item Design -->
<LinearLayout xmlns:android=""
    android:padding="5dip" >

        android:textStyle="bold" >

The file defines a class called ListAdapterModel that extends ArrayAdapter class. The object of the ListAdapterModel class will be used as the data source of the list. Below is the content of the ListAdapterModel. java file.

ListAdapterModel. java file

package com.example.bclean;

import java.util.ArrayList;
import android.content.Context;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListAdapterModel extends ArrayAdapter<String>{
int groupid;
ArrayList<String> titles;
ArrayList<String> urls;
ArrayList<Bitmap> bitmaps;
Context context;
String path;
public ListAdapterModel(Context context, int vg, int id, ArrayList<String> titles,ArrayList<String> urls,ArrayList<Bitmap> bitmaps){
super(context,vg, id, titles);

public View getView(int position, View convertView, ViewGroup parent) {

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View itemView = inflater.inflate(groupid, parent, false);
        ImageView imageView = (ImageView) itemView.findViewById(;
        TextView textTitle= (TextView) itemView.findViewById(;
        String title=titles.get(position);
        TextView textURL = (TextView) itemView.findViewById(;
        String url=urls.get(position);
        //make the url clickable
        Linkify.addLinks(textURL, Linkify.ALL);
        return itemView;


The most important file in this application is file. This file contains code that reads, display  the browser history and bookmarks, and clean the history data.
In the onCreate method of the MainActivity class, three ArrayList objects are created by calling the createLists method. One ArrayList object is to store the titles of the browser history and bookmarks. One is for storing the urls. And the last one will store the icons. The three ArrayList objects will be supplied to the ListAdapterModel class to show the browser history and bookmarks on the list. file

package com.example.bclean;
import java.util.ArrayList;
import android.os.Bundle;
import android.provider.Browser;
import android.content.ContentResolver;
import android.database.Cursor;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {

    private ArrayList<String> titles;
    private ArrayList<String> urls;
    private ArrayList<Bitmap> bitmaps;
    private ContentResolver cr;
     protected void onCreate(Bundle savedInstanceState) {
    protected void onResume(){
    public void createLists(){
    titles=new ArrayList<String>();
    urls=new ArrayList<String>();
    bitmaps=new ArrayList<Bitmap>();
    public void getBH(){
    Bitmap icon;
    String order=Browser.BookmarkColumns.DATE+" DESC";
    String[] projection={Browser.BookmarkColumns.TITLE,Browser.BookmarkColumns.URL,Browser.BookmarkColumns.FAVICON};
    //String selection=projection[0]+"=?";
    //String args[]={"Google"};
    Cursor rows=cr.query(Browser.BOOKMARKS_URI,projection, null,null,order);
    while(rows.moveToNext()) {
    //read title
    String title=rows.getString(rows.getColumnIndex(projection[0]));
    //read url
    String url=rows.getString(rows.getColumnIndex(projection[1]));
    //read icon
    byte[] bicon=rows.getBlob(rows.getColumnIndex(projection[2]));
    //convert blob image data to Bitmap
    //default icon for history and bookmarks that do not icons
    //add to lists
    //close the cursor
    public void addToList(String title,String url, Bitmap bitmap){

    public void showHistoryBookmarks(){
    ListView l=(ListView) findViewById(;
ListAdapterModel aa=new ListAdapterModel(this,R.layout.listlayout,,titles,urls,bitmaps);  
Toast.makeText(this, "This is no bookmark or history.", Toast.LENGTH_SHORT).show();

    public void cleanHB(){
    Browser.clearHistory(cr); //clear history data
    createLists(); //recreate the lists
    onResume(); //update the list
    public boolean onCreateOptionsMenu(Menu menu) {
        //Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(, menu);
        return true;
    public boolean onOptionsItemSelected(MenuItem item){
    return false;


The getHB method reads the browser history and bookmarks from Android and add the data (titles, urls, and icons) on the list. To get the browser history and bookmarks from Android, you will use the ContentResolver class. The instance of this class can be obtained by invoking the getContentResolver method from the current activity. By using the query method of the ContentResolver class, you can read all browser history and bookmarks. These history and bookmarks are stored in a Cursor object. The query method has five arguments. The first argument accepts the url that the data will be read from. This app reads the browser history and bookmarks. Thus, the url is BOOKMARKS_URI from the Browser class. The second argument allows you to specifiy an array of fields or column names to be retrieved. In this app, their are only three fields that will be retrieved TITLE, URL, and FAVICON. You will need to use the BookmarkColumns class in Browser class to access the field names of the table that stores the browser history and bookmarks. The third and forth arguments specifies the selection (field and operator) and selection arguments (values) to retrieve the rows of the table. Since the app retrieves all rows, you will use null values for these arguments. The last argument of the query method allows you to specify the field that the rows will be ordered by.
The title, and urls are text (string). The icon field is of Blob type. The data in Blob type can be converted to the Bitmap by using the decodeArrayByte method of the BitmapFactory class.
The showHistoryBookmarks will be called after the getHB method to display the titles, urls, and icons of the browser history and bookmarks on the list. In this method, the ListAdapterModel object is created and the titles, urls, and icons are passed to it.
The cleanHB method is called when the user touches the clean menu item. It will remove all history data from Android. The list will be updated to reflect the change by calling the onResume method. You will need to edit the main.xml file (in menu folder) to add the clean item to the menu. Here is the content of the main.xml file.
main.xml file

<menu xmlns:android="" >



Before running the BClean app, you also need to edit the AndroidManifest.xml file to allow the application to read and write browser history and bookmarks. Please add the following permissions to the file.

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

Download the apk file of the BClean app

compass app flashLight app


  1. Great post, thanks!!
    Can you let me know how to add date and time stamps?
    also how to export the browser history list to a text file on the sd card?


    1. Ok i have managed to get the date/time stamp in the list. But now instead of exporting this list to SD card, is there any way to send this list automatically via email at a scheduled time?

    2. How to add date&time stamp in the list?

    3. Amazing Article, thank you!. I just wish to give you a big thumbs up for the excellent post. Kindly keep updating your blog. Java Developer is a dream career for IT students.To start wonderful Career to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training from India .

      or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

  2. Great Post!!!!
    Thanks for your valuable posting, it was very informative. Am working in Erp Software Company In India

  3. does it takes browser history and bookmarks from all the browsers like chrome,mozilla,ucbrowser etc

  4. This comment has been removed by the author.

  5. Vương Lâm nói tên ra, thiếu niên nghe xong, nhất thời ngạc nhiên, thất thanh nói:

    - Ngươi chính là Vương Lâm hả, phế... kia dựa vào tự sát mới tiến vào Hằng Nhạc Phái.

    Nói đến đây, hắn cảm thấy ngượng, cười nhẹ nói:

    - Bạn hữu, ta gọi là Trương Hổ, đừng để trong lòng, hiện tại trong phái hầu như không ai là không biết ngươi, ngươi cũng đừng trách ta vừa rồi nói như vậy, thực ra ta rất bội phục ngươi, lại có thể sử dụng như vậy phương pháp tiến vào.
    học kế toán thực hành
    forum rao vặt cattleya
    học kế toán tổng hợp
    chung cư eco-green-city
    học kế toán thực hành
    học kế toán tại bắc ninh
    dịch vụ kế toán trọn gói
    chung cư hà nội
    dịch vụ làm báo cáo tài chính
    kế toán cho quản lý
    khoá học kế toán thuế
    keny idol
    trung tâm kế toán tại long biên
    trung tâm kế toán tại hải phòng

    Vương Lâm cười khổ, cũng không thanh minh, lại đưa qua mấy củ khoai lang.

    Trương Hổ vội vàng tiếp nhận, sau ăn mấy khẩu ngượng ngùng nói:

    - Vương Lâm, ngươi vẫn là chừa cho mình chút đi, ngươi mới tới đây, không biết con chồn tạp vụ ở đây trong lòng tâm địa gian xảo, chờ ngày mai ngươi làm việc sẽ biết rõ, con mẹ nó, hắn quả thực sẽ không nhìn những đệ tử ký danh chúng ta như con người!
    Chương 11: Trương Hổ
    - Con chồn?

    Vương Lâm giật mình, người thứ nhất hắn nghĩ đến chính là người thanh niên áo vàng lúc trước cười nhạo mình, cảm thấy hắn có vẻ phù hợp với danh hiệu này, nhưng trong lòng không biết rốt cuộc đối phương nói có đúng là hắn ta hay không.

    - A? Ngươi chưa nhìn thấy hắn? Chính là thằng cha phụ trách an bài công tác của ký danh đệ tử, hắn cũng là ký danh đệ tử, chẳng qua đã đạt được tư cách tu luyện tiên pháp, mặc áo vàng, vừa nhìn đã thấy không phải là người tốt gì, giống như một con chồn con, chúng ta thường ở đằng sau vụng trộm gọi hắn như vậy.

    Trương Hổ nuốt nước miếng, nghiến răng nghiến lợi giải thích.

  6. When I enter this source code on Android Studio it does some errors

  7. I always like and search such topics and everything connected to them.Excellent and very cool idea and the subject at the top of magnificence ..
    Weblogic Training in Chennai

  8. why it shows only local history? how to show full history from google acount ?

  9. Your post, regarding Android App Development is very effective for learners. I have got some important suggestions from it. I'm working in Brave Technologies Private Limited.BRAVE TECHNOLOGIES is a leading ERP software company offering best quality cost effective software applications and end to end enterprise solutions. We are experts in Mobile App development on both platforms – Android & iOS.

  10. Hello, Thanks for this valuable post. It's working fine in Android 4.0.1 version. Not working with greater then android 4.1 version. Can you suggest me how to get browser history for Android 5.0 or greater than this.

  11. Hello. Do you know how to get the history and bookmarks option in case of an Android Dictionary App... that has an option to access the history of the recently searched words and also an option to bookmark a particular word for quick access?

  12. Thanks for posting useful information.You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...Really it was an awesome article...very interesting to read..
    please sharing like this information......
    Android training in chennai
    Ios training in chennai

  13. I am expecting more interesting topics from you. And this was nice content and definitely it will be useful for many people.
    Mobile App Development Company
    Mobile App Development Company in India
    Mobile App Development Companies

  14. Your website content nice nice and interesting to observe.
    jobbörse Neunkirchen

  15. I found a lot of interesting information here. Really good post
    office 2010 professional download

  16. The website is looking bit flashy and it catches the visitors eyes. A design is pretty simple .

  17. Your website content nice nice and interesting to observe.
    jobbörse Neunkirchen

  18. I read this article. I think You put a lot of effort to create this article. I appreciate your work.
    Dissertation Writing Services

  19. problems with pls

    1. Your Error is the same of what i got my project have you reach on solution and share with me

  20. Thank you for your precious information. very clear explanation.Please share more like that..
    Construction Services

  21. I have learnt quite a lot about creating a simple Android app to view browser history and bookmarks by reading this post. Many thanks for sharing this invaluable information. Feel free to click on Professional Writing Services | Writing Academic Papers

  22. Hello Admin I have tried to build this history project through all the steps you share us but when i reach on in MainActivity GiHB method >> BookmarkColumns it show me an error may you help me to fix this

  23. Searching for Dissertation Writing Services as Your Dissertation Has Become a Nightmare for You? In Search of a Trustworthy Dissertation Writing Service So As to Complete Your Degree with Distinction!Why students search for reliable dissertation writing services online
    cheap dissertation Writing Services

  24. Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You ! Kindly Visit Us @ Coimbatore Travels | Ooty Travels | Coimbatore Airport Taxi | Coimbatore taxi | Coimbatore Taxi

  25. افضل شركة تنظيف منازل بالرياض
    تعتبر أعمال التنظيف من أهم المجالات التى لابد من الاهتمام بها لتحافظ على سلامة الاثاث الخاص بك فسرعان ما يتعرض الاثاث للاتساخات نتيجة كثيرة الاستعمال بالاضافه الى الاطفال اللذين لديهم دور كبير فى تلوث الاثاث واتساخه لذلك نحن كشركة نظافة نعتمد على أدوات مميزة وحديثة.
    شركة تنظيف فلل بالرياض -شركة تنظيف موكيت بالرياض -شركة تنظيف كنب بالرياض - شركة تنظيف واجهات بالرياض -شركة تنظيف بيوت شعر بالرياض

  26. To do Not Pressure OR Anything, But Have Ever This considered post there is statement PT Lampung Service this is a
    Service HP Bandar Lampung whose looking to do day
    Iklan Baris Lampung to this looking then to out standing that is
    Business Of Luxury Design I will try it.
    Jasa Kursus Service HP They have jumping places and so that the device other kid's activity.Youtuber Lampung ,

    Thanks ! Visit Back Subscribel Here ->Youtuber Lampung <-


  27. Information from this blog is very useful for me, am very happy to read this blog Kindly visit us @ Luxury Watch Box | Shoe Box Manufacturer |  Candle Packaging Boxes

  28. I love it... I've never tried the texture paste before but now I will. Love the numbers!

  29. I love this post.

    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    สมัครสล็อตออนไลน์ >>> goldenslot
    สนใจร่วมลงทุนกับเรา สมัครเอเย่น Gclub คลิ๊กได้เลย

  30. Very cool!

    เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
    เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา สมัคร Gclub Royal1688
    และยังมีหวยให้คุณได้เล่น สมัครหวยออนไลน์ ได้เลย
    สมัครสมาชิกที่นี่ >>> Gclub Royal1688

  31. Great post very informative thanks for sharing.

  32. I appreciate your effort and want you to keep on posting such posts
    Android internship in kochi

  33. This comment has been removed by the author.

  34. Great work, excellent content as usual. I am Working in a mobile app development company in riyadh

  35. Thank you for sharing in this article Great extra tips i am working in a Website Development Company Vancouver

  36. Thank you for the information you provide, it helped me a lot! it's great

    ios development course in kochi

  37. Prior to stumbling upon this post, I didn't know that creating an Android app to view browser history and bookmarks can be that simple. Thanks a lot for sharing this information. Feel free to click on Professional Marketing Company. We assure you that once you click on that link, you will get online marketing services that will meet if not surpass your expectations.

  38. Your blog posts are more interesting and impressive. I think there are many people like and visit it regularly, including me.I actually appreciate your own position and I will be sure to come back here.

    ecommerce development company in kochi

  39. well written article. I’ll be sure to bookmark it and return to read more of your useful info. Thanks for the post. I will definitely return.

    website development company in kochi

  40. This comment has been removed by the author.

  41. Its very best of best content and, I learn some thing very complicated on different blogs everyday. I think You put a lot of effort to create this topic blog. I appreciate your work and, thank you so much for this sharing. best assignment help -
    plagiarism checker -
    assignment writing help

  42. Striking to take a gander at your blog once more, it's been an especially drawn out time period for me. I need this article to complete my school task. Appreciative to you. The user is 24 * 7 available on affected devices. Check the simple solution if there is Hp Error Code oxc19a0003.

  43. This is the kind of article information to read whenever you want to understand more about outsourcing. Personally, I have really benefited and so marvelous from reading it. I can’t wait to read more of your new content. Thanks for sharing and Good luck for new updates. taxation law assignment help -
    corporate finance assignment help -
    nursing assignment help

  44. While utilizing the printer in the event that it stalls out in the center of the work, it can raise the temper of the user. We have seen numerous canon putting their questions dependent on canon printer in error state issue, for instance what do I do if my standard printer is in error state?, how would I get my ordinance printer out of error state, etc. Subsequently, to settle every one of these inquiries we have the arrangement and it is referenced beneath.
    canon printer in error state

  45. Assignment help in Saudi Arabia allows students to finish their papers on time without having any mistakes. If you want to submit error-free papers in your universities, you must think about Online Assignment help in Saudi Arabia.