package com.example.flipkartwebview;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private WebView webView;
private EditText editText;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
editText = findViewById(R.id.editText);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
String url = request.getUrl().toString();
Log.d("WebView", "shouldOverrideUrlLoading: " + url);
editText.setText(url);
return false; // Allow WebView to load the URL
}
@Override
public void onPageStarted(WebView view, String url, android.graphics.Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Log.d("WebView", "onPageStarted: " + url);
editText.setText(url);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.d("WebView", "onPageFinished: " + url);
editText.setText(url);
}
@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
Log.d("WebView", "onLoadResource: " + url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
Log.e("WebView", "onReceivedError: " + failingUrl + " - " + description);
}
});
webView.loadUrl("https://www.flipkart.com");
}
}
I’m trying to make a simple webbrowser first as example I’m opening webpage https://flipkart.com/
then when I’m doing some work like any product click or any other work webview not getting the specific url which I can show on addressbar.
as time of when I’m interacting with product or try to login everything working as expected just not getting actual url like chrome show on address bar or any other browser shows on addressbar.
How to fix this issue??
New contributor
Hodol Kutkut is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.