Previously, we implemented browser bookmarks in Android. Now we can add and delete bookmarks as follows:
First, add the write permission to bookmark in androidmainfest. xml:
<Uses-Permission Android: Name = "com. Android. browser. Permission. write_history_bookmarks"/>
Then add two methods to the activity.
Adding bookmarks is simple. assign values to contentvalues and call the insert method of contentresolver.
Private void insertbookmark (){
Contentvalues inputvalue = new contentvalues ();
// The bookmark value is 1.
Inputvalue. Put (browser. bookmarkcolumns. Bookmark, 1 );
// Add a bookmarks title
Inputvalue. Put (browser. bookmarkcolumns. title, "witmob ");
// Add a bookmark URL
Inputvalue. Put (browser. bookmarkcolumns. url,
"Http://bigcat.easymorse.com /");
Contentresolver = getcontentresolver ();
// Add the bookmarks to the browser
Contentresolver. insert (browser. bookmarks_uri, inputvalue );
}
The method for deleting bookmarks is as follows:
Private void deletebookmark (){
Contentresolver = getcontentresolver ();
// Delete bookmarks
Int number = contentresolver. Delete (browser. bookmarks_uri,
Browser. bookmarkcolumns. Title + "=? And"
+ Browser. bookmarkcolumns. url + "=? ", New string [] {
"Witmob", "http://bigcat.easymorse.com /"});
}
The delete method of contentresolver requires three parameters. The first parameter is Uri, and the second parameter is similar to the where condition of the SQL statement. Here is:
Browser. bookmarkcolumns. Title + "=? And "+ browser. bookmarkcolumns. url +" =? "
The third parameter is "?" In the second where parameter. Assign values. The order must correspond to each other. Here, the first string array corresponds to the title and the second corresponds to the URL.
Source code link: http://bigcateasymorse.googlecode.com/svn/trunk/androidbookmark1.1/