Android Wing of mucchin | Content Providers related



How to add, update and delete bookmarks in a browser from Android application


Method from the Android app, add a bookmark of the browser, update, or delete?

Last time, I'll show you how to get the apps from the Android browser bookmarks.
How to get apps from the Android browser bookmarks

There may also be made from Android apps yourself, that you want to add a bookmark in your browser.
For example, instead I'll be using Android's apps for free, or to bookmark my site? (Let's leave it like spam.)
Or make an Android app or just like a bookmark editor.

This time, we will show you how to add to the bookmark.

How to Add bookmarks in a browser

Will be like the following sample code.


Browser.saveBookmark (this, "senki", "http://android.roof-balcony.com");


Because it is final static method that is defined in the Browser class, call the above is OK simply Shiteyare.
The first argument is of type Context, so do I specify the (Activity) their own, and is this. Activity and if it was implemented as a separate class, let's suitable variable.
The second argument is the title, the third argument is a URL.
However, it is not anything displayed on the screen, does not mean you can register to bookmark smoothly.
When you run the saveBookmark method, the following screen will be displayed.
How to Add bookmarks in a browser from Android application


According to the API reference, it is apparently referred to as "AddBookmark activity."
This screen also change the URL also edit the title, it is the mercy of the user, can also be canceled.
If you thought Yara various security aspects, it's a user-friendly specification, may be good that way ·.

Means without going through the screen as described above, Why do not you save a bookmark! ?
The Browser class, method to save a bookmark, it is only programmed () method saveBookmark.
I tried to validate the way I'm going to add other than saveBookmark method.
Bookmarks and etc. However, we have held in the local database.
They can be manipulated by the straight! ? I have tried.
Code like the following.


ContentValues ​​values ​​= new ContentValues ​​();
values.put (Browser.BookmarkColumns.BOOKMARK, "1");
values.put (Browser.BookmarkColumns.URL, "http://android.roof-balcony.com");
values.put (Browser.BookmarkColumns.TITLE, "android");
. getContentResolver () insert (Browser.BOOKMARKS_URI, values);


When you move to implement the above code, SecurityException has occurred.
Look at the log, and set the permissions, I tried to move again to add the com.android.browser.permission.WRITE_HISTORY_BOOKMARKS.
Then, we will have succeeded in dazzling Add Bookmark.

In the Browser class, so methods can delete or update the bookmark does not seem to exist.
However, I think that was able to be added as described in the previous, and they can also · be removed or updated, we give this a try.




How to remove the browser's bookmarks

Is first removed.


getContentResolver (). delete (
Browser.BOOKMARKS_URI,
Browser.BookmarkColumns.TITLE + "= 'android'", null);


In the above code, the bookmark you just added has disappeared.

How to update your browser bookmarks

Likewise updated, and try the code like the following,


ContentValues ​​values ​​= new ContentValues ​​();
values.put (Browser.BookmarkColumns.BOOKMARK, "1");
values.put (Browser.BookmarkColumns.URL, "http://android.roof-balcony.com");
values.put (Browser.BookmarkColumns.TITLE, "android");
getContentResolver (). update (
Browser.BOOKMARKS_URI,
values, Browser.BookmarkColumns.TITLE + "= 'senki'", null);


The above is a record of "senki" title, was able to update the value set in values.


Looking at the API reference for Android, in the Browser class-related writing only bookmark does not exist () method saveBookmark.
This is why I would.
What a trick of how to write with ContentResolver insert was obtained in the (), update, a delete, update Did you mean to do is direct, not to do getContentResolver?
Not have deep meaning, or would just simply do not offer?

I do not know why, but well, anyway, erasing the user's bookmarks or maliciously, or I rewrite, let's stop spam in the Android app!

2 3 4 5 ... 10 ... Last » A ten page of a two three 4 five ... 10 ... Last »