简体   繁体   English

在WebView中加载自定义URL

[英]Loading custom url in webview

In my app, i am loading "http" url in the webview. 在我的应用程序中,我正在Webview中加载“ http” URL。 This url is loaded correctly, but there are some internal url's loaded with the protocol "sheet://". 此网址已正确加载,但协议“ sheet://”已加载了一些内部网址。 While loading this url i get an error "protocol isn't supported". 加载此网址时,出现错误“不支持协议”。 Can anyone please help how to fix this? 谁能帮忙解决此问题? How to load the url's with the protocol "sheet://" ? 如何使用协议“ sheet://”加载网址?

PS: I am using shouldOverrideUrlLoading method to load the url. PS:我正在使用shouldOverrideUrlLoading方法加载网址。

This is the code I am using 这是我正在使用的代码

 public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(url.contains("sheet://")){
          Intent url_intent = new Intent ( Intent.ACTION_VIEW,Uri.parse(url));
          url_intent.addCategory(Intent.CATEGORY_BROWSABLE);
          startActivity(url_intent);
          return false; 
        }else{
              view.loadUrl(url);
              return true; 
        }
 }

Thanks & Regards, 感谢和问候,

Perhaps host an PHP file, with an header? 也许托管一个带有标头的PHP文件?

<?php
header("Location: sheet://link_to_your_file.extention");
?>

Do you see the call to shouldOverrideUrlLoading come in for your sheet:// URL? 您是否看到Sheet:// URL调用了shouldOverrideUrlLoading That part of the code looks correct (assuming there is an app installed on your device that can handle sheet:// BROWSABLE intents). 这部分代码看起来正确(假设您的设备上安装了可以处理sheet:// BROWSABLE意图的应用程序)。 Or do you mean that the app launched from your app cannot load the sheet:// URL? 还是意味着从您的应用启动的应用无法加载sheet:// URL? What app is being launched to respond to the Intent? 正在启动什么应用程序来响应意图?

One mistake you have is the call to loadUrl when sheet:// is not in the URL. 您遇到的一个错误是在sheet:// 不在 URL中时调用loadUrl In this case, please just return true . 在这种情况下,请return true The URL load is already in progress, there is no need to start it again. URL加载已在进行中,无需再次启动。 Doing so infact creates a loop. 这样做实际上会创建一个循环。

您必须在AndroidManifest.xml中使用与该协议匹配的意图过滤器注册活动

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

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