0

I am trying to open my WebView app from URLs from browser and Google Search.

I tried using the following code as suggested here: How to launch app on click of url in android

    <intent-filter>
        <data android:scheme="https" />
        <data android:scheme="https" android:host="www.webviewurl.com"/>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>

But it didn't work.

I want to force open all URLs like:

https://*.webviewurl.com/*
http://webviewurl.com/*

to https://www.webviewurl.com/* in the WebView.

I've already done this part in the server using .htaccess.

I want the URLs to open in WebView by default.

Maroof Mandal
  • 521
  • 9
  • 29

1 Answers1

-1

The issue has been resolved by doing the following:

AndroidManifest.xml

            <intent-filter>
                <data android:scheme="https" />
                <data android:scheme="https" android:host="www.webviewurl.com"/>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>

MainActivity.java

public class webclient extends WebViewClient {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if(url.contains("play.google")){
                view.getContext().startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            }
            if ((url.contains("webviewurl.com"))) {
                view.loadUrl(url);
                return true;
            } else {
                view.getContext().startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            }
            return true;
        }

Which is working fine. Only problem is, all the pages are opening the homepage in app.

Like if an user clicks on a link say https://www.website.com/folder/page from browser, it opens https://www.website.com/ in the app.

How do I fix this issue?

Maroof Mandal
  • 521
  • 9
  • 29