title: Open Link from Browser in Android Webview
body: <p>I would like to open links in browsers with the host <code>example.com</code> or <code>example.de</code> in my Android application with webview.<br>
  I created this intent:</p>
  
  <pre><code>&lt;intent-filter&gt;
      &lt;data android:scheme="https" android:host="example.com" /&gt;
      &lt;data android:scheme="https" android:host="example.de" /&gt;
      &lt;data android:scheme="http" android:host="example.com" /&gt;
      &lt;data android:scheme="http" android:host="example.de" /&gt;
  
      &lt;action android:name="android.intent.action.VIEW" /&gt;
      &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
      &lt;category android:name="android.intent.category.DEFAULT" /&gt;
  &lt;/intent-filter&gt;
  </code></pre>
  
  <p>By default, the WebView loads the URL <code>example.com</code>, here is my onCreate:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
  
      this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  
      setContentView(R.layout.activity_main);
  
      final ProgressDialog pd = ProgressDialog.show(this, "", "Loading...", true);
  
      mWebView = (WebView) findViewById(R.id.activity_main_webview);
  
      // Enable Javascript
      WebSettings webSettings = mWebView.getSettings();
      webSettings.setJavaScriptEnabled(true);
  
      // Stop local links and redirects from opening in browser instead of WebView
      mWebView.setWebViewClient(new MyAppWebViewClient());
  
      mWebView.setWebViewClient(new WebViewClient() {
  
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
              pd.show();
              view.loadUrl(url);
              return true;
          }
  
          @Override
          public void onPageFinished(WebView view, String url) {
              if (pd.isShowing() &amp;&amp; pd != null) {
                  pd.dismiss();
              }
          }
      });
  
      mWebView.loadUrl(url);
  }
  </code></pre>
  
  <p>This is my shouldOverrideUrlLoading():</p>
  
  <pre><code>    @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
  
          if(Uri.parse(url).getHost().endsWith("example.com") || Uri.parse(url).getHost().endsWith("example.de") ) {
              return false;
          }
  
          Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
          view.getContext().startActivity(intent);
          return true;
      }
  </code></pre>
  
  <p>Now I am stuck. If you click on the URL <code>example.com/otherurl.php</code> in a web browser, the app opens, but loads the default url <code>example.com</code>. How can I open the app and load <code>example.com/otherurl.php</code> instead of <code>example.com</code>?  <br><br>
  I already read <a href="https://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser">here</a>, that I need this piece of code to get the url:</p>
  
  <pre><code>Uri data = getIntent().getData();
  String extUrl = data.toString();
  </code></pre>
  
  <p>But where should I implement this code?
  Thanks</p>