-3

I have a requirment like ,i need to launch an app from a link in mail which will work for both android and iphone

i tried redirecting to webpage from link in mail and from there i ll open app based on os but this is working fine in ios,not in android. i have attached code

$(document).ready(function() {

    if (navigator.userAgent.indexOf('iP') != -1) {

    setTimeout(function() {
        document.location = 'http://www.test.com';
    }, 300);

    self.location = "testapp://";
    } else if (navigator.userAgent.indexOf('Android') != -1) {

        document.location = 'http://www.test.com';     
    } else {
        alert('windows');
    }
});

any ideas...i am breaking my head on this req for a week .....

Avilam
  • 21
  • 1
  • 5

2 Answers2

1

On android at least you can make your app listen for, and offer to react to certain urls.

So you can set an IntentFilter to listen for http://yoururl.com/somestuff and whenever that url is clicked the user will be presented with a list of applications that are capable of handling it, which will include yours, and most likely any browsers loaded on the devce. I have no guidance for iOS though, not sure if the same thing is possible.

FoamyGuy
  • 45,328
  • 16
  • 118
  • 151
  • thanks for your reply.i tried this already it is working but when u come out of app it will navigate to mail not home grid of mobile.any ideas? – Avilam Apr 04 '13 at 14:33
  • It should navigate to mail, that will be the previous thing in the Activity stack. This is the default behavior of the OS, it will be what users are expecting, since everything else on the device functions that way. But if you are dead set on breaking the activity stack flow, you can manually launch the intent to start the launcher inside of onStop() of your activity that handles the link. – FoamyGuy Apr 04 '13 at 14:36
  • yeah,i agree with your answer.but thing is suppose i launched app from link in mail,and in between if i press home button on mobile and again if i press gmail,it is showing app(particular screen which went to background state when i pressed home) not the gmail..thats why i asked this question – Avilam Apr 04 '13 at 14:45
  • You should have included that in the question itself then, we had no way to know that =). And one potential solution to that is make your activity have `android:noHistory="true"` in your manifest. – FoamyGuy Apr 04 '13 at 14:52
1

Solution for Android: Make a link in the Android browser start up my app? (stack overflow)

Solution for iOS: iPhone apps: Can I open an app from a link in a website? (stack overflow)

Solution with the same link?

You could try to provide the same url scheme (prefix) - never tried that before. Otherwise you need to link to a server and that does a redirect. But this is a bad behavior because this would open the browser first and then open your app.

Community
  • 1
  • 1
mr.VVoo
  • 2,245
  • 18
  • 29
  • thanks for your reply,i tried both approaches as u suggessted for same link,problem with first approach is i cannot give common scheme for ios like http://test.com , bcoz in iphone we can give custom scheme like myapp://test.com...any ideas? – Avilam Apr 04 '13 at 14:50
  • i tried second approach like redirecting to webpage it is working fine in iphone but as you said it opens webpage first and then app.but its not working in android at all.i had attached my code also...plz go thru it if possible...give me some ideas.... – Avilam Apr 04 '13 at 14:54