1

我正在制作一个演示应用程序,其中我想通过单击按钮在后台打开浏览器,并且必须在打开浏览器后阅读浏览器 URL 栏文本。我怎样才能达到同样的效果。是否可行。我发现这是为了阅读 URL ,但是我不清楚如何在后台打开浏览器。

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();

谢谢

4

1 回答 1

1

尝试

 CookieStore cookieStore = new BasicCookieStore();

 HttpContext localContext = new BasicHttpContext();
// Bind custom cookie store to the local context
  localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
  HttpClient http = new DefaultHttpClient();
 HttpPost post = new HttpPost(url);
 HttpResponse response = null;
try {
    response = http.execute(post,localContext);
} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
String str=(String) localContext.getAttribute("last_redirect_url");
               if (str == null)
                {
                   HttpUriRequest currentReq = (HttpUriRequest) localContext.getAttribute(ExecutionContext.HTTP_REQUEST);
                   HttpHost currentHost = (HttpHost)  localContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
                   str = (currentReq.getURI().isAbsolute()) ? currentReq.getURI().toString() : (currentHost.toURI() + currentReq.getURI());
                  System.out.print(str); 
               } 
}
于 2013-04-22T08:01:33.093 回答