简体   繁体   English

链接正在加载外部应用程序(浏览器)问题

[英]Links are loading in external app (Browser) issue

I'm showing this website's "https://www.egkhindi.com/" homepage on my app by using this code我正在使用此代码在我的应用程序上显示此网站的“https://www.egkhindi.com/”主页

MainActivity.java MainActivity.java

package com.example.appthree;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.Window;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        String Htmlurl = "https://www.egkhindi.com/";
        WebView view = (WebView) this.findViewById(R.id.webView);
        view.getSettings().setJavaScriptEnabled(true);
        view.loadUrl(Htmlurl);


    }
}

This is coming fine but when I'm clicking any link on app , an external browser comes up to load that link.这很好,但是当我单击 app 上的任何链接时,会出现一个外部浏览器来加载该链接。 Is there any fix to load every external link in my app ?是否有任何修复程序可以加载我的应用程序中的每个外部链接?

for this, you have to create webViewController Class to load view inside app webview为此,您必须创建 webViewController 类以在应用程序 webview 中加载视图

Make changes in your code as below如下更改您的代码

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String Htmlurl = "https://www.egkhindi.com/";
        WebView view = (WebView) this.findViewById(R.id.webView);
        view.getSettings().setJavaScriptEnabled(true);
        view.setWebViewClient(new webViewController()); // added webViewController here  
        view.loadUrl(Htmlurl);


    }

    // Webview Controller to handle view inside app webview
    private static class webViewController extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) { 
            view.loadUrl(url); // to loading view inside webview and return true
            return true;
        }
    }
    
}

I hope it helps.我希望它有所帮助。

use this settings for your webView :为您的 webView 使用此设置:

kotlin:科特林:

view.webViewClient = object : WebViewClient() {
    override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
        view.loadUrl(url)
        return true
    }               
}

java:爪哇:

view.setWebViewClient(new mWebViewClient());
private static class mWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
        view.loadUrl(url); // to loading view inside webview and return true
        return true;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何直接在应用内浏览器(Chrome 自定义选项卡)中打开外部链接,而不提示浏览器 select - How to open external links directly in in-app browser (Chrome custom tab) without getting prompt to select the browser 如何在浏览器中打开外部 WebView 链接? - How to Open External WebView Links in Browser? 我希望在浏览器中打开外部链接 - I want external links to open in my browser 如何使用外部浏览器在WebView中打开目标_blank链接 - how to open target _blank links in WebView with external browser Android WebView app err_unknown_url_scheme(mailto,外部链接,网站内部链接) - Android WebView app err_unknown_url_scheme (mailto, external links, website internal links) 加载我的应用程序时出现 android 生命周期问题 - android lifecycle issue while loading my app 将毕加索的图像从外部驱动器加载到RecyclerView中-Android应用 - Loading Images with Picasso into RecyclerView from External Drive - Android App 无法从外部浏览器连接到EC2 Web应用 - Cannot connect to EC2 web app from external browser 向Android App WebView添加后退按钮/主页功能和外部浏览器 - Adding Back Button/Home Function and External Browser to Android App WebView 如果应用使用网络浏览器链接,如何通过Google Play商店的Android TV资格? - How to pass Google Play Store eligibility for Android TV if app uses web browser links?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM