Android Wing of mucchin | 20th page: Home



How to get apps from the Android browser bookmarks


How to get the app from the Android browser bookmarks?

Android Apps from to create your own, there are ways to access the browser's bookmarks.
As with call logs that we introduced earlier, you can use a mechanism called content providers.


When you use the basic usage of the content provider, you can use the () method (). Query getContentResolver.
However, when you get a bookmark of the browser, rather than how to use the method in this way, which is implemented in the Browser class is easy.

How to get the browser's bookmarks

The first step is to introduce the sample code when using () method (). Query getContentResolver.
This method is look at the API reference, or I feel like this? Code and tried.
Also in the API reference, only constant is listed, a detailed description is not written anything.
Is something like the following.


String [] projection = new String [] {
Browser.BookmarkColumns.BOOKMARK,
Browser.BookmarkColumns.CREATED,
Browser.BookmarkColumns.DATE,
Browser.BookmarkColumns.FAVICON,
Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL,
Browser.BookmarkColumns.VISITS
;}

Cursor c =
getContentResolver (). query (
Browser.BOOKMARKS_URI, projection, null, null, null);

if (c.moveToFirst ()) {
do {
/ /} While the processing of each record (c.moveToNext ());
}
c.close ();


Specifies the URI (). query that, "Browser.BOOKMARKS_URI" () method getContentResolver.
Looking at the records retrieved by this URI, as well as bookmarks, would gain up to (URL was accessed at a time) history.
Browser.BookmarkColumns.BOOKMARK column called, I think would be a flag indicating whether it bookmarked.
So, if you wish to receive only the bookmarks, you need to specify the conditions in the third argument () method (). Query getContentResolver. (The sample code above has to null.)
However, API reference, since you have not written anything a description of each column of records to be retrieved is Browser.BOOKMARKS_URI, I think this way and It is not a desirable way.




So, there is a way to get information about only the most easily bookmark correctly.

Browser.getAllBookmarks () method

The Browser class has a method called getAllBookmarks ().
If you get a bookmark, you can use this method.
Let's take a look at the sample code.
Rewrite the previous example.


Cursor c = Browser.getAllBookmarks (getContentResolver ());
if (c.moveToFirst ()) {
do {
/ /} While the processing of each record (c.moveToNext ());
}
c.close ();


And use () method, I will quite refreshing Browser.getAllBookmarks.
And this way, such as a list of URL URL history is not balanced, that you can get registered in the bookmark.
Record, the URL is because it is state, ID is in the second column in the second column one, if you want to get the URL string, you get as shown below.


String url = c.getString (0);
Or
String url =
c.getString (c.getColumnIndex (Browser.BookmarkColumns.URL));


The former method, that has changed If you encounter specification tables, then I would shift the position of the column, you will not be properly balanced.
The latter method might be to write verbose, you might want here.
However, since I do not know whether or not I change some specifications bookmark table is stored, I do not even say the former might.
It is the same in the latter the name of the column is the first place if I were changed ·. Is not it Well.

In addition, to obtain from the Android browser bookmarks, it is necessary to set the permission.
Read and write permissions bookmark

Next time, you will learn how to add bookmarks.

10 ... 18 19 20 21 22 ... 30 40 50 ... Last » Page 20 of eighty-one «First ... ten ... 18 nineteen twenty twenty-one twenty-two ... thirty forty 50 ... Last »