First of all: AJAX won't help you there because it cannot be used to open
links. It can only be used to load resources from your own website.
What you can do is inserting a hidden iframe object. When the user clicks
the link to open that app then let some JavaScript code set the "src"
attribute of that hidden iframe object to your app's launcher URL. If the
app is installed it should work. If not the 404 error message should be
hidden:
<script type="text/javascript>
> function startApp() {
> document.getElementById('hiddenIframe').src = "LAUNCHER_URI_GOES_HERE";
> }
> </script>
>
> <iframe id="hiddenIframe" style="display:none" />
>
> <a href="javascript:startApp()">Start app</a>
>
Unfortunately there is no way to check whether an URI has been successfully
loaded in an iframe. What you could try to do is using some time
measurement to figure out whether your app has been launched by starting a
timer when the launcher link has been clicked. Set the timer to 1 second or
something like that. Cancel the timer when your window loses focus
(window.onblur event). When your window does NOT lose focus and the timer
runs out you can show an error popup that says that the app is not
installed.
I'm not sure whether this will really work, because I did not test the
window.onBlur event on webkit but it should be worth a try:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var timeout;
window.onblur = function() {
// Cancels the pending warning message
if(timeout) clearTimeout(timeout);
};
function appNotInstalled() {
alert('App not installed');
}
function startApp() {
document.getElementById('hiddenIframe').src = "LAUNCHER_URI_GOES_HERE";
timeout = setTimeout(appNotInstalled, 1000);
}
</script>
</head>
<body>
<iframe id="hiddenIframe" style="display:none"></iframe>
<a href="javascript:startApp()">Start app</a>
</body>
</html>
On Monday, February 4, 2013 5:21:00 AM UTC-6, Mark Cz wrote:
>
> Hi All,
>
> I know how to launch activity from web, many has been written regarding
> the subject,
> http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser
>
> The problem is I have got the href for launching the application on my
> personal page, but the user doesn't have necessarily my application.
> My question is how to *detect *if the intent exists on the phone. If it
> doesn't I get 404, and if it does it launches the intent. I want to catch
> the 404, and display an alert or even do nothing.
> I tried using $.ajax or *href *with no much help,
>
> Please advise.
>
>
>
>
--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.