我正在制作一个演示应用程序,我想在按钮单击后在后台打开浏览器,并在浏览器打开后阅读浏览器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();
由于
答案 0 :(得分: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);
}
}