1

How to delete bookmark you get from

android.provider.Browser.BOOKMARKS_URI

I got bookmark listed, how to get history of website visited?

EDIT

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.add(0, MENU_ITEM_DELETE, 0, "DELETE");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_ITEM_DELETE:
        int urlIndex = mCursor.getColumnIndex(Browser.BookmarkColumns.URL);
        String url = mCursor.getString(urlIndex);
        contentResolver.delete(Uri.parse(url), item.getTitle().toString(), null);
    }
    return false;
}

What can I do in:

contentResolver.delete(Uri.parse(url), item.getTitle().toString(), null);

to delete bookmark at that listview position when long click on that bookmark?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user1205012
  • 11
  • 1
  • 3

1 Answers1

1

First you need to get ContentResolver instance.

you can get it as follows:

ContentResolver cr = ctx.getContentResolver();

ctx is Context instance.

then there is a delete method in ContentResolver, signature is as follows:

delete(url, where, selectionArgs)

put your url in place of url(Url.parse("android.provider.Browser.BOOKMARKS_URI")), a valid where clause and selection arguments. and you are done.

Then you need to add some permissions as per your implementations. But i guess you would need these:

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

you can get more info about this on the following link

also refer this link.

Thanks

Community
  • 1
  • 1
N-JOY
  • 10,344
  • 7
  • 51
  • 69