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
Related
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;
}
I'm trying to implement the following behavior into my Android App.
The app is a native app with some parts using WebView, in this WebView there is the possibility of using different payment methods.
If the user has the app of that bank installed I want to be able to open the corresponding app. In some cases, the website loaded into the WebView launch a specific intent:// that I can easily intercept and try to redirect the user to the app, but for the cases where the website use the new Android App link I'm not able to intercept them because they are normal https:// calls.
I tried to load the Android App link into Chrome and this way the app is opened.
My question at this point is how I can replicate the behavior of Chrome into my WebView??
I didn't find that much informations on this specific case besides the Android Documentation
Thanks for your help :)
You can intercept the url click by using custom WebViewClient for the webview.
1)Set the custom webview client for the webview
2)Override the below method and return true (you can do this based on particular url also. )
shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
3)Override below method and handle the click and start the activity using either package name or playstore url with intent.
public void onLoadResource (WebView view,
String url)
WebView mWebView;
WebViewClient customWebClient = new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request){
//This can be modified based on the url . URL can be retrieved using request.getUrl()
return true;
}
#Override
public void onLoadResource(WebView view, String url){
if( url.equals("") ){
// launch playstore activity
final String appPackageName = "package name of the application"
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
}
}
}
mWebView.setWebViewClient(customWebClient);
I have an android app, there is an activity with a webView, it acts like a browser (it open some links I provided). Whenever I browse through my webView if there is a link that leads to play store to download an app my webView can't respond, it says 'webpage not available'. It can't send an intent to open play store or something like google chrome. How can I do it?
This works for me and opens play store app if it is installed and else shows playstore
link within the same webView.
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) {
Uri uri = Uri.parse(url);
view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
return false;
}
}
return false;
}
});
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);
}
});