Android本地应用程序在webview中打开
我正在开发一个应用程序,它应该显示一个网页,并从该网页中的链接打开另一个应用程序,我们称之为otherApp。我使用WebView在我的应用程序中显示网页Android本地应用程序在webview中打开,android,android-webview,Android,Android Webview,我正在开发一个应用程序,它应该显示一个网页,并从该网页中的链接打开另一个应用程序,我们称之为otherApp。我使用WebView在我的应用程序中显示网页 WebView myWebView = (WebView) findViewById(R.id.webview); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); myWebView.setWebViewCli
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().indexOf("example")>0) {
// This is my web site, so do not override;
//let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch
// another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
});
myWebView.loadUrl("https://www.example.com/demo.html");
demo.html文件包含以下链接:
<a href="otherapp://"> Start otherApp </a>
使用平板电脑的浏览器,点击链接打开otherApp,Chrome仍在运行。但是,当使用我的应用程序时,otherApp会在WebView中打开,我需要两个应用程序彼此独立运行。代码取自developer.android.com,我正在使用运行棉花糖的Nexus7平板电脑
你知道我遗漏了什么吗