Click here to Skip to main content
15,889,631 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

With the code of MainActivity.java of android studio I can get my URL loaded correctly, but, I get "ERR_UNKNOWN_URL_SCHEME" when trying to tap on links that starts with tg: (Telegram).

Anyone can help me to solve this issue, please? Unfortunately, I am a complete beginner in android java code. Please guide me where to put the code to resolve the tg: telegram link issue.
Thanks.
Java
package com.tesco.webview;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
    private WebView mywebView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mywebView=(WebView) findViewById(R.id.webview);
        mywebView.setWebViewClient(new WebViewClient());
        mywebView.loadUrl("https://example.com/");
        WebSettings webSettings=mywebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
    }
    public class mywebClient extends WebViewClient{
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon){
            super.onPageStarted(view,url,favicon);
        }
        @Override
        public boolean shouldOverrideUrlLoading(WebView view,String url){
            view.loadUrl(url);
            return true;

        }
    }
    @Override
    public void onBackPressed(){
        if(mywebView.canGoBack()) {
            mywebView.goBack();
        }
        else{
            super.onBackPressed();
        }
    }
}


What I have tried:

I'm a beginner in android development. So I have tried other solutions but they dont worked that's why I'm asking questions here.
Posted
Comments
Richard MacCutchan 13-Mar-21 4:49am    
The prefix tg: is not valid in a webrequest. Where are these links that you are trying to access?
sagarjkhatri 13-Mar-21 5:36am    
It t.me/pphott link which is a telegram link inside the website(mywebView.loadUrl("https://supertesco.com"); that I'm trying to make a webview app.
Richard MacCutchan 13-Mar-21 5:43am    
Sorry, I have no idea what that means. It does not look like a valid URL.
sagarjkhatri 13-Mar-21 5:47am    
Sir t.me/pphott is the link I'm trying to access which is a telegram link.
Richard MacCutchan 13-Mar-21 5:49am    
That is not a valid URL, it needs the http:// or https:// prefix.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900