gpt4 book ai didi

android - 在后台打开浏览器并在 Android 中读取浏览器 URL 文本

转载 作者:行者123 更新时间:2023-11-30 03:38:56 25 4
gpt4 key购买 nike

我正在制作一个演示应用程序,其中我想在单击按钮时在后台打开浏览器,并且在打开浏览器后必须读取浏览器 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();

谢谢

最佳答案

尝试

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

关于android - 在后台打开浏览器并在 Android 中读取浏览器 URL 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16140748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com