【问题标题】:How to set WebView permission for all domain like google map link whatsapp chat link如何为所有域设置 WebView 权限,如谷歌地图链接 whatsapp 聊天链接
【发布时间】:2021-03-21 21:57:11
【问题描述】:

嘿,我是 android studio 的新手,我正在制作 webview 应用程序。我的应用程序在同一个域上完美运行,但是当我打开其他域链接时没有打开。 App Error Screenshot

例如。 example.com 是我的主要 webview 应用 URL。网站在此域上完美运行,但是当我想打开 secondexample.com 等其他域链接或其他域站点时,网站无法打开。这是我的代码,请帮助我坚持这个我对此进行了研究,但没有找到解决方案。

public class MainActivity extends Activity {
    private WebView mywebView;

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

        mywebView = (WebView) findViewById(R.id.webview);
        WebSettings webSettings = mywebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mywebView.loadUrl("https://nishaboutique.online/");

        mywebView.setWebViewClient((new WebViewClient()));

        // Improve performance

        mywebView.getSettings().setAllowFileAccess(true);
        mywebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
        mywebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        mywebView.getSettings().setAppCacheEnabled(true);
        mywebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        webSettings.setDomStorageEnabled(true);
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        webSettings.setUseWideViewPort(true);
        webSettings.setSavePassword(true);
        webSettings.setSaveFormData(true);
        webSettings.setEnableSmoothTransition(true);
    }

【问题讨论】:

标签: android android-studio web webview mobile-website


【解决方案1】:

使用这个link。它显示了类似的错误。解决方案是添加 network_security_config.xml 文件并更新清单文件。

newtwork_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
        <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">api.example.com(to be adjusted)</domain>
        </domain-config>
</network-security-config>

如果这不起作用,请考虑将 url 从“http”更改为“https”。

【讨论】:

  • 无法使用whatsapp 聊天链接和谷歌地图链接。同样的错误给出。
  • 这可能是因为您可能需要登录这些网站。
  • 我使用 android studio 的 webview 功能将我的网站转换为移动应用程序。在我的网站中,一些链接(例如 whatsapp 聊天或谷歌地图方向链接)会在新点击中打开并连接到那里的应用程序。但在我的 webview 应用程序中,此链接不起作用,显示错误“ERR_UNKNOWN_URL_SCHEME”如何解决。所以这个链接在外部浏览器或特定应用程序中打开。
猜你喜欢
  • 2012-03-23
  • 1970-01-01
  • 2021-02-04
  • 2022-12-17
  • 1970-01-01
  • 1970-01-01
  • 2021-10-03
  • 2015-06-15
  • 1970-01-01
相关资源
最近更新 更多