I am trying to add a bookmark through code to the Android browser. I am able to do that successfully in the emulator, but the same code is not working on the device.
Note开发者_运维问答: when I query, the bookmarks database, the URL is there. It's just not able to display in the device.
This is my code snippet
ContentValues cv = new ContentValues();
cv.put(Browser.BookmarkColumns.TITLE, cursor.getString(1));
cv.put(Browser.BookmarkColumns.URL, cursor.getString(2));
cv.put(Browser.BookmarkColumns.BOOKMARK, 1);
Uri u = getContentResolver().insert(Browser.BOOKMARKS_URI,cv);
Where am I going wrong?
I have tested your code snippet and it works, bookmark was added to my Browsers native application (tested on 2.2 HTC Desire). All I had to add to your code was a permission in the AndroidManifest.xml:
<uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS" />
Thats because it gets saved in the wrong folder. To be displayed it needs to be stored in the browsers homepage folder (folder id 0), but by default it gets stored in the folder id 99. See my console output:
Displaying correctly: title: Ringtones bookmark:1 folder:0
Not showing up: title: Google bookmark:1 folder:99
Unfortunately I didn't find out to change this so far...
精彩评论