Reputation: 416
I'm working on a Java-based Android app.
I wanna open links inside my app's WebView
as long as URLs are HTTP
and open URLs that include HTTPS
in my default browser.
I have tried this code but it always opens in WebView even though I open URLs that include HTTPS
.
This is my code:
//URLs
webv.loadUrl(Const.PATH_RESTAURANT + "res.pl?resUID=" + LoginActivity.mUserCD);
//condition to check url
if (Const.PATH_RESTAURANT.contains("https")) {
//open in default web browser
webv.setWebChromeClient(new WebChromeClient());
} else {
//open in webview
webv.setWebViewClient(new WebViewClient());
}
Upvotes: 1
Views: 67
Reputation: 13288
Use Intent.ACTION_VIEW
//condition to check url
if (Const.PATH_RESTAURANT.contains("https")) {
//open in default web browser
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.example.com"));
startActivity(intent);
} else {
//open in webview
webv.setWebViewClient(new WebViewClient());
}
Upvotes: 2