1

how to start third activity if url is same in webview

for example i have webview in my webview if url is like this

http://example.com/access.html

then start thirdactivity

how can i do this please help me to fix this issue thanks

in advance

here is my webview code

public class SecondActivity extends AppCompatActivity {

    private WebView wv1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        String url = getIntent().getStringExtra("url");
        wv1=(WebView)findViewById(R.id.webView);
        wv1.setWebViewClient(new WebViewClient());
        wv1.getSettings().setLoadsImagesAutomatically(true);
        wv1.getSettings().setJavaScriptEnabled(true);
        wv1.loadUrl(url);
    }




}

here is xml file of secondactivity

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimaryDark"

    tools:context="com.shuvro.barcodescanner.BarcodeScannerActivity">


    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>
user1833487
  • 145
  • 2
  • 13
  • Possible duplicate of [How to start an activity when a link is clicked in webview?](https://stackoverflow.com/questions/17788362/how-to-start-an-activity-when-a-link-is-clicked-in-webview) – AskNilesh Mar 22 '18 at 10:55

2 Answers2

1
 webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap 
      favicon) {
            super.onPageStarted(view, url, favicon);
       // write your logic here.
            if (url.equals(pdfWebURL)) {
                loadingIndicator.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            loadingIndicator.setVisibility(View.GONE);
        }
    });

please write your logic in onPageStarted.

Vishal Sojitra
  • 486
  • 3
  • 10
0

Please try below code

public class WebView extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String weburl) {
        if (weburl.equals("YOURLINK")) {
            Intent i = new Intent(getContext(), YourActivity.class);
            startActivity(i);
            return true;
        } else {
            view.loadUrl(url);
            return true;
        }
    }
}
Shanto George
  • 994
  • 13
  • 26