Android как скопировать url из webview

от admin

Как получить URL текущей страницы из веб-просмотра в Android

Используя метод webview.loadUrl(url) , я открываю URL-адрес. Если я нажмю на Button на просмотр, он перейдет на другую страницу. Теперь я хочу получить URL-адрес страницы. как я могу его получить?

Я также хочу, чтобы содержимое отображалось в веб-просмотре. Как получить содержимое WebView ?

4 ответа

см. мой ответ может это поможет вам.

Я предполагаю, что вы установили WebViewClient . Если вы не можете сделать это, как показано ниже,

Здесь, когда вы нажимаете на любую ссылку на WebView , тогда она вызывается shouldOverrideUrlLoading() , и вы можете получить текущий url там в currentUrl .

это самый простой способ для этого API > 20: Существуют, очевидно, другие методы, в которых парсерам, таким как HTMLCleaner, больше управлять. Тем не менее, это полезно и просто для получения URL. Каждый раз, когда URL-адрес изменяется в Webview, URL-адрес в объекте запроса также изменяется.

вы также можете сделать свой вызов, переопределив onpagefinished метод webviewclient. Я хотел бы отметить это, поскольку это называется, когда страница заканчивает загрузку.

how to get the current page url from the web view in android

Using webview.loadUrl(url) method I open an url. If I click any Button on the view it directs to another page. Now I want to get the url of the directed page. how can I get it?

I also want the content that is displayed on the webview. How to get the content of the WebView ?

4 Answers 4

Vinayak Bevinakatti's user avatar

please see my answer may it will help you.

V.P.'s user avatar

I am assuming that you have set your WebViewClient .If not then you can do like below,

Here when you click on any link on the WebView then it will call shouldOverrideUrlLoading() and you can get the current url there in currentUrl .

Spring Breaker's user avatar

this is the most simple way of handling this for API > 20: There are obviously other methods with parsers like HTMLCleaner to have more control. However, this is good and simple for getting URL. Each time URL changes in Webview, URL in the request object changes as well.

you can also make your call by overriding onpagefinished method of webviewclient. I wanted to note this, since this is called when page finishes loading.

akemko's user avatar

    The Overflow Blog
Linked
Related
Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.3.11.43304

Читать:
Как пользоваться программой cdburnerxp

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Android. Как из WebView открыть ссылку типа tel:// (телефон)?

Есть мини-приложение, которое состоит из WebView. (открывается сайт в нем, а сайт как бы и есть приложение).
И ссылки типа tel:// (номер телефона) не открываются, в самом приложении пишется что документ недоступен (т.е. пытается открыть как страницу).

В приложении всего пара функций

Вот как бы сделать так, что бы по переходу по ссылки типа tel:// в приложении, тело ссылки передавалось в приложение телефон.

  • Вопрос задан более трёх лет назад
  • 1019 просмотров
  • Facebook
  • Вконтакте
  • Twitter

Немного корявый язык . Лучше быстро не нагуглилось :
www.ohandroid.com/setwebviewclient-setwebchromecli.
WebViewClient – это интерфейс событий. Предоставляя собственную реализацию WebViewClient, вы можете реагировать на события рендеринга. Например, вы можете обнаружить, когда рендер начинает загружать изображение с определенного URL-адреса или решает, повторно отправить запрос POST на сервер.

У WebViewClient есть много методов, которые вы можете переопределить, большинство из которых вы не будете иметь дело. Однако вам нужно заменить стандартную реализацию shouldOverrideUrlLoading(WebView, String) для shouldOverrideUrlLoading(WebView, String) . Этот метод определяет, что произойдет, когда новый URL-адрес будет загружен в WebView, например, нажав ссылку. Если вы вернете true, вы говорите: «Не обрабатывайте этот URL-адрес, я сам обрабатываю его». Если вы вернете false, вы говорите: «Идите и загрузите этот URL-адрес, WebView, я ничего с ним не делаю «.

How to get Title and URL from android.webkit.WebViewClient and show inside app’s ActionBar TitleBar.

In this tutorial we are making simple android application with the combination of WebView in it but we are covering more important topic inside this project which is Getting current opening URL and Webpage Title( Which we will open inside android app using WebView ) and display that Title + URL into Action bar like we have already seen inside every android web browser. So here is the complete step by step tutorial for Get Show loaded webpage Title and URL from WebView in android.

How to Get Show loaded webpage Title and URL from WebView in android app’s ActionBar.

Note : Please add Internet permission inside your AndroidManifest.xml file.

Code for MainActivity.java file.

Code for activity_main.xml layout file.

Code for AndroidManifest.xml file.

Screenshots:

webview-title

Get Show loaded webpage Title and URL from WebView in android app

Click here to download Get Show loaded webpage Title and URL from WebView in android app’s ActionBar project with source code.

Похожие статьи