I need to take url after loading a web page in my web view to check condition and if I use onPageFinished() method, then where to use.
Asked
Active
Viewed 452 times
0
-
https://stackoverflow.com/a/3149260/3154636 – Ashish Kudale Jan 30 '19 at 06:38
-
https://stackoverflow.com/questions/3149216/how-to-listen-for-a-webview-finishing-loading-a-url – Amin Pinjari Jan 30 '19 at 06:38
-
https://stackoverflow.com/questions/27693490/android-how-get-url-in-page-loaded-loading – Amin Pinjari Jan 30 '19 at 06:38
-
Possible duplicate of [How to listen for a WebView finishing loading a URL?](https://stackoverflow.com/questions/3149216/how-to-listen-for-a-webview-finishing-loading-a-url) – Tejas Pandya Jan 30 '19 at 06:41
-
@aminpinjari where should I use that method, either in same Activity or in the other class. If in another class, how to use – Manjunath Jan 30 '19 at 06:45
-
use it in same class where your webview is implemented – Amin Pinjari Jan 30 '19 at 06:48
1 Answers
0
Just set a webview client and override onpagefinished as shown below
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = findViewById(R.id.webview);
webView.loadUrl("http://www.google.com");
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Toast.makeText(getApplicationContext(), url,Toast.LENGTH_LONG).show();
}
});
}
}
inside onpagefinished you have the url

hushed_voice
- 3,161
- 3
- 34
- 66