Add and delete browser bookmarks in Android

Source: Internet
Author: User

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/

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.