[英]How to set WebView permission for all domain like google map link whatsapp chat link
hey I'm new on android studio im making webview app.嘿,我是 android 工作室的新手,我正在制作 webview 应用程序。 my app working perfectly on same domain but when i open other domain links then not opening.
我的应用程序在同一个域上完美运行,但是当我打开其他域链接时没有打开。 App Error Screenshot
应用程序错误截图
ex.前任。 example.com is my main webview app URL.
example.com是我的主要 webview 应用程序 URL。 website lode and work perfectly on this domain but when i want to open other domain link like secondexample.com or other domain sites then website not opening.
网站在此域上完美运行,但是当我想打开其他域链接(如secondexample.com或其他域站点)时,网站无法打开。 here is my code please help I'm stuck on this i reserched about this but no solution find.
这是我的代码,请帮助我坚持这个我对此进行了研究,但没有找到解决方案。
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);
}
Use this link .使用此链接。 It shows a similar error.
它显示了类似的错误。 The solution is to add a network_security_config.xml file and update your manifest file.
解决方案是添加 network_security_config.xml 文件并更新您的清单文件。
newtwork_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>
If this doesn't work, consider changing the url from "http" to "https".如果这不起作用,请考虑将 url 从“http”更改为“https”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.