Browserpublic class Browser extends Object
Fields Summary |
---|
private static final String | LOGTAG | public static final android.net.Uri | BOOKMARKS_URIA table containing both bookmarks and history items. The columns of the table are defined in
{@link BookmarkColumns}. Reading this table requires the
{@link android.Manifest.permission#READ_HISTORY_BOOKMARKS} permission and writing to it
requires the {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS} permission. | public static final String | INITIAL_ZOOM_LEVELThe name of extra data when starting Browser with ACTION_VIEW or
ACTION_SEARCH intent.
The value should be an integer between 0 and 1000. If not set or set to
0, the Browser will use default. If set to 100, the Browser will start
with 100%. | public static final String | EXTRA_APPLICATION_IDThe name of the extra data when starting the Browser from another
application.
The value is a unique identification string that will be used to
identify the calling application. The Browser will attempt to reuse the
same window each time the application launches the Browser with the same
identifier. | public static final String | EXTRA_HEADERSThe name of the extra data in the VIEW intent. The data are key/value
pairs in the format of Bundle. They will be sent in the HTTP request
headers for the provided url. The keys can't be the standard HTTP headers
as they are set by the WebView. The url's schema must be http(s).
| public static final String[] | HISTORY_PROJECTION | public static final int | HISTORY_PROJECTION_ID_INDEX | public static final int | HISTORY_PROJECTION_URL_INDEX | public static final int | HISTORY_PROJECTION_VISITS_INDEX | public static final int | HISTORY_PROJECTION_DATE_INDEX | public static final int | HISTORY_PROJECTION_BOOKMARK_INDEX | public static final int | HISTORY_PROJECTION_TITLE_INDEX | public static final int | HISTORY_PROJECTION_FAVICON_INDEX | public static final int | HISTORY_PROJECTION_THUMBNAIL_INDEX | public static final int | HISTORY_PROJECTION_TOUCH_ICON_INDEX | public static final String[] | TRUNCATE_HISTORY_PROJECTION | public static final int | TRUNCATE_HISTORY_PROJECTION_ID_INDEX | public static final int | TRUNCATE_N_OLDEST | public static final android.net.Uri | SEARCHES_URIA table containing a log of browser searches. The columns of the table are defined in
{@link SearchColumns}. Reading this table requires the
{@link android.Manifest.permission#READ_HISTORY_BOOKMARKS} permission and writing to it
requires the {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS} permission. | public static final String[] | SEARCHES_PROJECTIONA projection of {@link #SEARCHES_URI} that contains {@link SearchColumns#_ID},
{@link SearchColumns#SEARCH}, and {@link SearchColumns#DATE}. | public static final int | SEARCHES_PROJECTION_SEARCH_INDEX | public static final int | SEARCHES_PROJECTION_DATE_INDEX | private static final int | MAX_HISTORY_COUNT | public static final String | EXTRA_CREATE_NEW_TABBoolean extra passed along with an Intent to a browser, specifying that
a new tab be created. Overrides EXTRA_APPLICATION_ID; if both are set,
a new tab will be used, rather than using the same one. | public static final String | EXTRA_SHARE_SCREENSHOTStores a Bitmap extra in an {@link Intent} representing the screenshot of
a page to share. When receiving an {@link Intent#ACTION_SEND} from the
Browser, use this to access the screenshot. | public static final String | EXTRA_SHARE_FAVICONStores a Bitmap extra in an {@link Intent} representing the favicon of a
page to share. When receiving an {@link Intent#ACTION_SEND} from the
Browser, use this to access the favicon. |
Methods Summary |
---|
private static final void | addOrUrlEquals(java.lang.StringBuilder sb)
sb.append(" OR " + BookmarkColumns.URL + " = ");
| public static final void | addSearchUrl(android.content.ContentResolver cr, java.lang.String search)Add a search string to the searches database.
Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
// The content provider will take care of updating existing searches instead of duplicating
ContentValues values = new ContentValues();
values.put(Searches.SEARCH, search);
values.put(Searches.DATE, System.currentTimeMillis());
cr.insert(Searches.CONTENT_URI, values);
| public static final boolean | canClearHistory(android.content.ContentResolver cr)Returns whether there is any history to clear.
Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
Cursor cursor = null;
boolean ret = false;
try {
cursor = cr.query(History.CONTENT_URI,
new String [] { History._ID, History.VISITS },
null, null, null);
ret = cursor.getCount() > 0;
} catch (IllegalStateException e) {
Log.e(LOGTAG, "canClearHistory", e);
} finally {
if (cursor != null) cursor.close();
}
return ret;
| public static final void | clearHistory(android.content.ContentResolver cr)Delete all entries from the bookmarks/history table which are
not bookmarks. Also set all visited bookmarks to unvisited.
Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
deleteHistoryWhere(cr, null);
| public static final void | clearSearches(android.content.ContentResolver cr)Remove all searches from the search database.
Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
// FIXME: Should this clear the urls to which these searches lead?
// (i.e. remove google.com/query= blah blah blah)
try {
cr.delete(Searches.CONTENT_URI, null, null);
} catch (IllegalStateException e) {
Log.e(LOGTAG, "clearSearches", e);
}
| public static final void | deleteFromHistory(android.content.ContentResolver cr, java.lang.String url)Remove a specific url from the history database.
Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
cr.delete(History.CONTENT_URI, History.URL + "=?", new String[] { url });
| public static final void | deleteHistoryTimeFrame(android.content.ContentResolver cr, long begin, long end)Delete all history items from begin to end.
Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
String whereClause;
String date = BookmarkColumns.DATE;
if (-1 == begin) {
if (-1 == end) {
clearHistory(cr);
return;
}
whereClause = date + " < " + Long.toString(end);
} else if (-1 == end) {
whereClause = date + " >= " + Long.toString(begin);
} else {
whereClause = date + " >= " + Long.toString(begin) + " AND " + date
+ " < " + Long.toString(end);
}
deleteHistoryWhere(cr, whereClause);
| private static final void | deleteHistoryWhere(android.content.ContentResolver cr, java.lang.String whereClause)Helper function to delete all history items and release the icons for them in the
{@link WebIconDatabase}.
Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
Cursor cursor = null;
try {
cursor = cr.query(History.CONTENT_URI, new String[] { History.URL }, whereClause,
null, null);
if (cursor.moveToFirst()) {
cr.delete(History.CONTENT_URI, whereClause, null);
}
} catch (IllegalStateException e) {
Log.e(LOGTAG, "deleteHistoryWhere", e);
return;
} finally {
if (cursor != null) cursor.close();
}
| public static final android.database.Cursor | getAllBookmarks(android.content.ContentResolver cr)Return a cursor pointing to a list of all the bookmarks. The cursor will have a single
column, {@link BookmarkColumns#URL}.
Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
return cr.query(Bookmarks.CONTENT_URI,
new String[] { Bookmarks.URL },
Bookmarks.IS_FOLDER + " = 0", null, null);
| public static final android.database.Cursor | getAllVisitedUrls(android.content.ContentResolver cr)Return a cursor pointing to a list of all visited site urls. The cursor will
have a single column, {@link BookmarkColumns#URL}.
Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
return cr.query(Combined.CONTENT_URI,
new String[] { Combined.URL }, null, null,
Combined.DATE_CREATED + " ASC");
| public static final java.lang.String[] | getVisitedHistory(android.content.ContentResolver cr)Returns all the URLs in the history.
Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
Cursor c = null;
String[] str = null;
try {
String[] projection = new String[] {
History.URL,
};
c = cr.query(History.CONTENT_URI, projection, History.VISITS + " > 0", null, null);
if (c == null) return new String[0];
str = new String[c.getCount()];
int i = 0;
while (c.moveToNext()) {
str[i] = c.getString(0);
i++;
}
} catch (IllegalStateException e) {
Log.e(LOGTAG, "getVisitedHistory", e);
str = new String[0];
} finally {
if (c != null) c.close();
}
return str;
| private static final android.database.Cursor | getVisitedLike(android.content.ContentResolver cr, java.lang.String url)
boolean secure = false;
String compareString = url;
if (compareString.startsWith("http://")) {
compareString = compareString.substring(7);
} else if (compareString.startsWith("https://")) {
compareString = compareString.substring(8);
secure = true;
}
if (compareString.startsWith("www.")) {
compareString = compareString.substring(4);
}
StringBuilder whereClause = null;
if (secure) {
whereClause = new StringBuilder(Bookmarks.URL + " = ");
DatabaseUtils.appendEscapedSQLString(whereClause,
"https://" + compareString);
addOrUrlEquals(whereClause);
DatabaseUtils.appendEscapedSQLString(whereClause,
"https://www." + compareString);
} else {
whereClause = new StringBuilder(Bookmarks.URL + " = ");
DatabaseUtils.appendEscapedSQLString(whereClause,
compareString);
addOrUrlEquals(whereClause);
String wwwString = "www." + compareString;
DatabaseUtils.appendEscapedSQLString(whereClause,
wwwString);
addOrUrlEquals(whereClause);
DatabaseUtils.appendEscapedSQLString(whereClause,
"http://" + compareString);
addOrUrlEquals(whereClause);
DatabaseUtils.appendEscapedSQLString(whereClause,
"http://" + wwwString);
}
return cr.query(History.CONTENT_URI, new String[] { History._ID, History.VISITS },
whereClause.toString(), null, null);
| public static final void | requestAllIcons(android.content.ContentResolver cr, java.lang.String where, WebIconDatabase.IconListener listener)Request all icons from the database. This call must either be called
in the main thread or have had Looper.prepare() invoked in the calling
thread.
Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
// Do nothing: this is no longer used.
| public static final void | saveBookmark(android.content.Context c, java.lang.String title, java.lang.String url)Open an activity to save a bookmark. Launch with a title
and/or a url, both of which can be edited by the user before saving.
Intent i = new Intent(Intent.ACTION_INSERT, Browser.BOOKMARKS_URI);
i.putExtra("title", title);
i.putExtra("url", url);
c.startActivity(i);
| public static final void | sendString(android.content.Context context, java.lang.String string)Sends the given string using an Intent with {@link Intent#ACTION_SEND} and a mime type
of text/plain. The string is put into {@link Intent#EXTRA_TEXT}.
sendString(context, string, context.getString(com.android.internal.R.string.sendText));
| public static final void | sendString(android.content.Context c, java.lang.String stringToSend, java.lang.String chooserDialogTitle)Find an application to handle the given string and, if found, invoke
it with the given string as a parameter.
Intent send = new Intent(Intent.ACTION_SEND);
send.setType("text/plain");
send.putExtra(Intent.EXTRA_TEXT, stringToSend);
try {
Intent i = Intent.createChooser(send, chooserDialogTitle);
// In case this is called from outside an Activity
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
c.startActivity(i);
} catch(android.content.ActivityNotFoundException ex) {
// if no app handles it, do nothing
}
| public static final void | truncateHistory(android.content.ContentResolver cr)If there are more than MAX_HISTORY_COUNT non-bookmark history
items in the bookmark/history table, delete TRUNCATE_N_OLDEST
of them. This is used to keep our history table to a
reasonable size. Note: it does not prune bookmarks. If the
user wants 1000 bookmarks, the user gets 1000 bookmarks.
Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
// TODO make a single request to the provider to do this in a single transaction
Cursor cursor = null;
try {
// Select non-bookmark history, ordered by date
cursor = cr.query(History.CONTENT_URI,
new String[] { History._ID, History.URL, History.DATE_LAST_VISITED },
null, null, History.DATE_LAST_VISITED + " ASC");
if (cursor.moveToFirst() && cursor.getCount() >= MAX_HISTORY_COUNT) {
/* eliminate oldest history items */
for (int i = 0; i < TRUNCATE_N_OLDEST; i++) {
cr.delete(ContentUris.withAppendedId(History.CONTENT_URI, cursor.getLong(0)),
null, null);
if (!cursor.moveToNext()) break;
}
}
} catch (IllegalStateException e) {
Log.e(LOGTAG, "truncateHistory", e);
} finally {
if (cursor != null) cursor.close();
}
| public static final void | updateVisitedHistory(android.content.ContentResolver cr, java.lang.String url, boolean real)Update the visited history to acknowledge that a site has been
visited.
Requires {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS}
Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
long now = System.currentTimeMillis();
Cursor c = null;
try {
c = getVisitedLike(cr, url);
/* We should only get one answer that is exactly the same. */
if (c.moveToFirst()) {
ContentValues values = new ContentValues();
if (real) {
values.put(History.VISITS, c.getInt(1) + 1);
} else {
values.put(History.USER_ENTERED, 1);
}
values.put(History.DATE_LAST_VISITED, now);
cr.update(ContentUris.withAppendedId(History.CONTENT_URI, c.getLong(0)),
values, null, null);
} else {
truncateHistory(cr);
ContentValues values = new ContentValues();
int visits;
int user_entered;
if (real) {
visits = 1;
user_entered = 0;
} else {
visits = 0;
user_entered = 1;
}
values.put(History.URL, url);
values.put(History.VISITS, visits);
values.put(History.DATE_LAST_VISITED, now);
values.put(History.TITLE, url);
values.put(History.DATE_CREATED, 0);
values.put(History.USER_ENTERED, user_entered);
cr.insert(History.CONTENT_URI, values);
}
} catch (IllegalStateException e) {
Log.e(LOGTAG, "updateVisitedHistory", e);
} finally {
if (c != null) c.close();
}
|
|