gpt4 book ai didi

android - 未知的 URL 方案

转载 作者:行者123 更新时间:2023-12-03 22:10:26 26 4
gpt4 key购买 nike

关闭。这个问题需要更多 focused .它目前不接受答案。












想改进这个问题?更新问题,使其仅关注一个问题 editing this post .


3年前关闭。







Improve this question




我有一个安卓WebView它使用 Intent 打印到收据打印机。使用 chrome 浏览器可以正常工作,但是当我打开时尝试使用 WebView 打印它给了我一条错误消息,如下所示

Webpage not available.
The webpage at
intent://....
net::ERR_UNKNOWN_URL_SCHEME.
我已经看到了以下链接,但我不确定如何实现它。
how-to-fix-unknown-url-scheme-in-android-webview
我不是安卓开发者。任何建议表示赞赏。

最佳答案

解决方案在您提供的链接中。

The WebView will usually recognize http and https, anything other than these, for example – intent://,market://,app://,mail:// etc will not be recognized by WebView unless we add a handler to handle these url schemes or by disabling these schemes and only load http and https schemes.



在您的 MainActivity 中进行测试。尝试使用 WebView 中的 url 打开一个简单的谷歌搜索窗口
public class MainActivity extends AppCompatActivity {

String url = "http://www.google.com";

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

final WebView webview = (WebView) findViewById(R.id.web1);
webview.loadUrl(url);

webview.setWebViewClient(new WebViewClient() {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);

if (url.startsWith("http") || url.startsWith("https")) {
return true;
} else {
webview.stopLoading();
webview.goBack();
Toast.makeText(MainActivity.this, "Unknown Link, unable to handle", Toast.LENGTH_SHORT).show();
}
return false;
}
});
}
}

关于android - 未知的 URL 方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54811265/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com