简体   繁体   中英

how to redirect the user to the (android ,ios) market when the app doesnt installed

Ihave an app that handles a custom URL scheme (Myapp://). When someone comes to a web page that has some Myapp:// content, we need to redirect them to the store if they don't have our app installed.

In android you can use Intents as url to open your app or redirect to google play if application not installed.


i need to do that from java script

You can change location like this:

window.location.href = "intent://test#Intent;package=com.test.app;end;";

For android, you need to mention the package name inside the url scheme like package=com.XYZ.ABC and then the android system will handle itself and open the play store if app is not present on the device. I'm not aware for IOS.

boolean installed = appInstalledOrNot("your package name");

if(!installed) 
{
  final String appPackageName = yourpackagename for the app to be installed; 
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)));
}
}

I've read your question very very thoroughly again. I hope I understand you correctly now:

  • you have an app
  • you have a web-page
  • if someone opens the web-page and they have your app installed, the app is launched?!
  • if someone opens the web-page and they don't have your app, they should be forwarded to the according appstore?!

For the last case: When you are using javascript, you should be able to check for the device type (with jQuery) and then do something like:

window.open('https://play.google.com/store/apps/details?id=' + yourPackageName);

see: redirect to appstore or google play

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM