For iOS you could use url schemes to direct users to your app, to check whether the app is installed on a device or not, do this.
if([[UIApplication sharedApplication] canOpenURL:[NSURL urlwithString:@"YourAppsScheme"]])
{
//your app is installed on the device, open your app using
[[UIApplication sharedApplication] openURL:[NSURL urlwithString:@"YourAppsScheme"]]
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL urlwithString:@"your applications itunes url"]] //
}
For Android you do the same kind of thing but you check the pacakge name exists on a device or not, How to check programmatically if an application is installed or not in Android?
sample snippet for Android:
installed = isPackageInstalled(APPPACKAGE);
if (installed) {
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage(APPPACKAGE);
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}
}
else
{
// open google play app details page of your app
final String appName = ...;
try
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName)));
}
catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+appName)));
}
}
private boolean isPackageInstalled(String packagename, Context context) {
PackageManager pm = context.getPackageManager();
try {
pm.getPackageInfo(packagename, GET_ACTIVITIES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
Doing this from a web page,
<script type="text/javascript">
function startMyApp()
{
document.location = 'yourAppScheme://';
setTimeout( function()
{
if( confirm( 'You do not seem to have Your App installed, do you want to go download it now?'))
{
document.location = 'http://itunes.apple.com/us/app/yourAppId';
}
}, 300);
}
</script>