开发者

how to get url string from browser

can i get url what i write on android device browser..

开发者_StackOverflow中文版please tell me..

thanks.


You can acces Browsing history the same way you do that for other ContentProviders. Besides browsing history you can also get list of Bookmarks. HISTORY_PROJECTION_BOOKMARK_INDEX is used to distinguish among them. You need permission com.android.browser.permission.READ_HISTORY_BOOKMARKS to execute this code.

Cursor webLinksCursor = getContentResolver().query(Browser.BOOKMARKS_URI, Browser.HISTORY_PROJECTION, null, null, Browser.BookmarkColumns.DATE + " DESC");
int row_count = webLinksCursor.getCount();

int title_column_index = webLinksCursor.getColumnIndexOrThrow(Browser.BookmarkColumns.TITLE);
int url_column_index = webLinksCursor.getColumnIndexOrThrow(Browser.BookmarkColumns.URL);

if ((title_column_index > -1) && (url_column_index > -1) && (row_count > 0))
{
    webLinksCursor.moveToFirst();
    while (webLinksCursor.isAfterLast() == false)
    {
        if (webLinksCursor.getInt(Browser.HISTORY_PROJECTION_BOOKMARK_INDEX) != 1)
        {
            if (!webLinksCursor.isNull(url_column_index))
            {
                Log.i("History" , "Last page browsed " + webLinksCursor.getString(url_column_index));
                break;
            }
        }
        webLinksCursor.moveToNext();
    }            
}
webLinksCursor.close();


My instinct tells me this is akin to reading the history, I can't see google allowing apps to access this data, it would be abused by malicious applications. However, if someone proves me wrong I'll be chosing my apps far more selectively in future!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜