-1

I want to open external links in web browser using intent and should not open in my WebView app except my internal links starts with "https://www.ecommerce.in/"
I have written code as given below:

@Override
 public boolean shouldOverrideUrlLoading(WebView view, String url) 
 {
  if (!url.contains("https://www.ecommerce.in/")) 
  {
   Uri uri = Uri.parse(url);
   startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), "Choose browser"));
   view.loadUrl(url);
   CookieManager.getInstance().setAcceptCookie(true);
  } else {
          webViewProduct.loadUrl(url);
          return true;
         }
 }    

This code is working perfectly as I want but the problem is when I pressed back button on web browser the same external link is opening in my WebView app.

Please let me know where I'm doing wrong. Thanks in advance.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ashok
  • 55
  • 1
  • 10

1 Answers1

0

You should have to remove view.loadUrl(url) from you code , So

Please replace your code as given below

@Override
 public boolean shouldOverrideUrlLoading(WebView view, String url) 
 {
  if (!url.contains("https://www.ecommerce.in/")) 
  {
   Uri uri = Uri.parse(url);
   startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, uri), "Choose browser"));

   CookieManager.getInstance().setAcceptCookie(true);
  } else {
          webViewProduct.loadUrl(url);
          return true;
         }
 }
ND1010_
  • 3,743
  • 24
  • 41
  • Thankyou. Its working fine. Could yo please help me about Fading Toolbar in WebView while scrolling up Toolbar Should fade to show and scrolling down Toolbar should fade to hide. I searched for this in Stack Overflow and in Google. But couldn't find any correct solution for this. Hope, I get a solution for this. Once again thank you for your help. – Ashok May 11 '18 at 14:10
  • ok you can prefer this link: https://stackoverflow.com/questions/14752523/how-to-make-a-scroll-listener-for-webview-in-android – ND1010_ May 12 '18 at 04:16
  • Hi, Than you for your support. I have tried the given link but it showing error message at _Log.d(TAG,"We Scrolled etc...");_ wv = (ObservableWebView) findViewById(R.id.scorllableWebview); wv.setOnScrollChangedCallback(new OnScrollChangedCallback(){ public void onScroll(int l, int t, int oldl, int oldt){ if(t> oldt){ //Do stuff System.out.println("Swipe UP"); //Do stuff } else if(t< oldt){ System.out.println("Swipe Down"); } Log.d(TAG,"We Scrolled etc..."); } }); – Ashok May 12 '18 at 17:10