Getting net::ERR_UNKNOWN_URL_SCHEME error
Asked Answered
L

1

6

I am trying to open a android application from javascript. If the android application is installed in android mobile, it opens required application. But if android application is not installed, it should give me the popup saying, "You do not seem to have app installed, do you want to download it now?". But I am getting net::ERR_UNKNOWN_URL_SCHEME error. I have added the code snippet below:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function redirectToApp() {
$('#link').attr('href', "<scheme>://<package>/?<parameters>");
$("#link")[0].click();
setTimeout(
        function() {
          if (confirm('You do not seem to have app installed, do you want to download it now?')) {
            window.location = 'https://play.google.com/store/apps/details?id=123';
                      } 
        }, 500);
}
</script>
</head>
<body onload="redirectToApp()">
<a id="link" href="" style="display: none">Link</a>
</body>
</html>
Lieu answered 4/1, 2018 at 12:42 Comment(0)
D
0

You could try to wrap the click in a try...catch. You said if the app is installed it works, so then you can assume if it fails that the app is not installed and then run the confirm.

try {
  $('#link').attr('href', "<scheme>://<package>/?<parameters>");
  $("#link")[0].click(); 
} catch (error) {
  if (confirm('You do not seem to have app installed, do you want to download it now?')) {
    window.location = 'https://play.google.com/store/apps/details?id=123';
  } 
}

You may also want to check that the error passed to catch is the net::ERR_UNKNOWN_URL_SCHEME that you expected too but maybe it is enough like this?

Drawback answered 4/1, 2018 at 12:57 Comment(5)
Hi, I tried with the above solution. But it does not seem to work. It is trying to open the app link (<scheme>://<package>/?<parameters>) and gives net::ERR_UNKNOWN_URL_SCHEME error.Lieu
@SwathiDelampady I presumed those were just placeholders, the link should use the real app protocol, url/package, and parameters. For example with the Google Maps app: maps://maps.google.com/maps?daddr=123,456Drawback
Hi, Those are just placeholders. It is trying to open my application link and throwing net::ERR_UNKNOWN_URL_SCHEME error. Is there any way to catch this error in javascript?Lieu
@SwathiDelampady That is not a JS error, I'm guessing it is Java that is throwing it so you can't catch it in JavaScript. Take a look here and try to solve it from the Java side: #24697929Drawback
We are trying login to android application through OKTA. After getting valid SAML response from OKTA in spring mvc, redirecting to JSP and opening android application's link. So we will not be having control over OKTA's web view.Lieu

© 2022 - 2024 — McMap. All rights reserved.