I have a webView online shop.
for some security reason I have to force my webView application to open payment page in user's default browser. I leave my code below for more information. but when that specific page open in browser it could not detect users credential and other important data like order number and etc.
How do I proceed to solve this?
Thank You All In Advance.
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// open in Webview
if (url.contains("https://example.com/checkout/confirmpaymentorder") ){
// if (Uri.parse(url).getHost().equals(getString(R.string.myhost)))
return false;
}
// open rest of URLS in default browser
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
Related
From this post I was able to create a functionality to redirect user to android or ios from a single link. However, on detection of Android I want to open the play store with my app shown. I tried the below link on redirect:
window.location.href = "https://play.google.com/store/apps/details?id=com.myapp";
but it opens the play store in the browser itself. I want to open the play store app, I am assuming that my app users will be having the play store app, so I do not want to check whether the play store app is installed or not. I also tried the market link as below
window.location.href = "market://details?id=com.myapp";
but this also does not work. Help appreciated.
I got it working by using the below url on redirect
window.location.href = "https://play.app.goo.gl/?link=https://play.google.com/store/apps/details?id=com.myapp";
When I visit this url from the browser of my mobile, it does not open the play store within browser but opens the play store app instead. This serves my purpose.
You can do this by checking URL in shouldOverrideUrlLoading method of your WebViewClient. See below
String market_url = "market://details?id=package_name";
String website_url = "https://play.google.com/store/apps/details?id=package_name";
onCreate ()
WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/index.html"); // path to html
webview.setWebViewClient(new Callback());
private class Callback extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.equals(website_url)) {
try {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(market_url));
startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
return (false);
}
}
index.html
App link
This will always open your link in play store.
I think a better way to do this could be
$(document).ready(function (){
if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
window.location.href = 'http://play.google.com/store/apps/details?id=com.truecaller&hl=en';
}
if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
window.location.href = 'http://itunes.apple.com/lb/app/truecaller-caller-id-number/id448142450?mt=8';
}
});
FB share button could successfully oepn the FB messenger app in Chrome browser.
However, the same source code, it fail to open the FB messenger app if display in Android APP application, and this application display web page using Chrome browser inside.
How to fix it?
You could provide a custom WebViewClient implementation to your WebView that checks for facebook.com links (or whatever links you like) and then explicitly fire an Intent so others can pickup the Action, instead of allowing the WebView to handle it as it sees fit.
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
Uri uri = Uri.parse(url);
if (uri.getHost().contains("facebook.com")) {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
return false;
}
} catch(Exception e){
e.printStackTrace();
}
return super.shouldOverrideUrlLoading(view, url);
}
});
I have a webview with custom webview client. I'm intercepting requests with:
#Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
// ...
}
sometimes I'm getting informations about custom events from webview in a form of a link:
xyz://do-something
When it happens I want webview to ignore it. But 'shouldInterceptRequest' has to return something and when I'm returning 'null' instead of my page it shows: 'unknown url xyz://do-something'. How can I deal with that? How can I intercept the link but disable action on webview side?
You just need to do a string comparison from the site that you are in and the site that you want to go to.
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// 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;
}
I have a Web App that loads locally html.
In one html, I have a link to a Google Play app, but the link opens inside the app, inside the webview.
On iOS devices any link https://itunes.apple.com/app/id000 will automatically open iTunes/App Store on the devices.
Is there a way to open the Google Play app directly from an html?
I'm trying _blank or the market:// as suggested on other questions, but nothing works.
App Link
App Link 2
Thanks!
you can use this it will work
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getScheme().equals("market")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
Activity host = (Activity) view.getContext();
host.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
// Google Play app is not installed, you may want to open the app store link
Uri uri = Uri.parse(url);
view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
return false;
}
}
return false;
}});
maybe this will help any one
Im using a webview to display a website.
The page iam opening using loadurl method is the login page,
on successful login redirection occurs to a particular page .
I want to skip that page i.e dont want to show that page rather show the webpage after that
eg If my webview starts with webpage A
on login success it shows webpage B
and then next page is webpage C
i want after Login success in page A it should go automatically to webpage C
current code im using
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url)
.getHost()
.equals("https://www.test.com")) {
web.loadUrl("https://www.test1.com");
}
return false;
}
so any tips/pointers as to how i do this?
thanks
Read this
You just need to do a string comparison from the site that you are in and the site that you want to go to.
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// 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;
}