简体   繁体   English

如何使浏览器打开不安全的链接而不显示错误消息

[英]How to make a browser open unsecured links without showing a error message

I am developing a web browser app to open only one specific link and no other options to open other links. 我正在开发一个web browser app ,它只能打开一个特定的链接,而不能打开其他链接。 With this app when I put a default link: https://www.google.com or any other links, the app works fine and it opens the link. 使用该应用程序,当我放置默认链接: https : //www.google.com或任何其他链接时,该应用程序可以正常工作并打开该链接。 But the link I want my app to open it is not opening and it is not even showing any error message. 但是我要我的应用程序打开的链接没有打开,甚至没有显示任何错误消息。 The link is this https://www.rdl.co.zw If I open this link with most known browsers like chrome and browser they show a security warning message with an option to continue or go back to safety. 链接为https://www.rdl.co.zw。如果我使用chrome和浏览器等大多数已知的浏览器打开此链接,它们将显示security warning message并可以选择继续或返回安全状态。 If I press continue the site will open. 如果我按继续,该站点将打开。 So what is the problem with my code and which code am I suppose to add to make my simple browser open this link even if the link is not secure. 那么我的代码有什么问题,我想添加哪些代码来使我的简单浏览器打开此链接,即使该链接不安全也是如此。 I want to open the link without showing a security warning message. 我想打开链接而不显示安全警告消息。

Check my code below and help me with what to add to make my app function: 检查下面的代码,帮助我添加使我的应用程序正常运行的内容:

public class MainActivity extends AppCompatActivity {

WebView webView;
SwipeRefreshLayout swipe;
SharedPreferences data;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getSupportActionBar().hide();


    swipe=(SwipeRefreshLayout)findViewById(R.id.swipe);
    swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            webAction();
        }
    });


    webAction();


}

private void webAction() {
    webView=(WebView)findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAppCacheEnabled(true);
    webView.loadUrl("https://www.rdl.co.zw");
    swipe.setRefreshing(true);
    webView.setWebViewClient(new WebViewClient(){
        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            swipe.setRefreshing(false);
        }
    });
}

@Override
public void onBackPressed() {
    if(webView.canGoBack()){
        finish();
    }else {
        finish();
    }
}

  }

Try adding this code to your manifest file and let me know if it solved your problem 尝试将此代码添加到清单文件中,让我知道它是否解决了您的问题

<manifest>
  <application>
     <meta-data android:name="android.webkit.WebView.EnableSafeBrowsing"
        android:value="false" />

  </application>
</manifest>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM