【问题标题】:Open Browser in Background and read the Browser URL Text in Android在后台打开浏览器并在 Android 中读取浏览器 URL 文本
【发布时间】:2013-04-14 23:30:23
【问题描述】:

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

谢谢

【问题讨论】:

  • 正如@Akilan 所说,您无需打开浏览器即可发出网络请求并获取所有信息
  • 感谢您的回复。但是如何?
  • 你为我提供了一种阅读历史的方法。这很好。但我想在发出一个网络请求后阅读它。而不是直接阅读。
  • 您的问题不清楚...您是否尝试发出网络请求...如果是这样,您不要以编程方式请求

标签: android browser


【解决方案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); 
               } 
}

【讨论】:

猜你喜欢
  • 2012-07-13
  • 1970-01-01
  • 2018-04-01
  • 1970-01-01
  • 2019-04-12
  • 2021-09-11
  • 1970-01-01
  • 2013-02-05
  • 1970-01-01
相关资源
最近更新 更多