Regarding the Browser not launching your app, it works for me if I use an HTML <a/> tag on my webpage.
Are you invoking your URL via JavaScript instead?
I ask because I know there is this “quirk” with Android’s WebView Java class where it’s WebViewClient.shouldOverrideUrlLoading() does not get called for URLs invoked via JavaScript… and that’s the method that most native Android developers use to override URL handling.
Out of interest, what issues were you having with a “singleTask” activity?
The only odd quirk that I’m aware of is if you display an activity from a singleTask activity, home out, and then go back to your app… then Android automatically destroys all of the activities displayed by that task and goes back to the singleTask activity.
I think in this forum I will get exact answer which I want
as Joshua has explained how to use URLScheme in android I m having one problem in this i want to open my application named “try”. what changes I have to do in it.
What you need to do is set up your “try” app with an intent-filter as I’ve shown up above. You can either give it a custom URL scheme or a the domain of your website. You would then launch your “try” app from your other app via Corona’s system.openURL() function. So, for the example I provided above which uses a “corona://” custom URL scheme, you would launch it like this…
system.openURL(“corona://test”)
Of course, you should use “corona” as your custom URL scheme. It should be unique to your app.
That said, I actually recommend that you do it by your website’s domain name instead in case the app you’re trying to launch is not installed. That way it’ll launch the device’s browser app instead and show a web page on your site telling the end-user to download your other app. Something along those lines. You would do this via the “data” tag’s “host” attribute instead of using the scheme “attribute” as documented by Google here…
If you have set up the URL handler like that, you can even launch it from the stock browser or Chrome. I have used it in several applications for some time now and it works entirely as expected. Thanks for making it possible.
I can launch one app from another with the method described here, but it does not seem to work if I want to launch the app from a browser or the email system. Is that supported?
Are you sure you have the category “android.intent.category.BROWSABLE” added to your filter, because this is required so that browser and e-mail will consider the intent-filter.
Hmm, I thought it did, but upon new try right now, it didn’t. Sorry, I had that wrongly in mind, because I only use it for bouncing between different apps, and I was pretty sure I also tested it with the settings, but I seem to have recalled that wrongly.
It works in the default Browser app for me. But it might not work for all 3rd party browser apps… or 3rd party apps in general. This is because it’s up to the 3rd party app to turn the URL into an Android “intent”, query if there are any activities on the device that support that URL scheme via PackageManager.queryIntentActivities() in Java, and then launching that activity. If the app does not do this and simply attempt to do an HTTP connection with your custom URL scheme, then of course it will fail. There is nothing you can do within your app to force another app to handle your custom URL scheme. Not even if you’ve coded your Android app natively.
So, this is why I’ve suggested up above to use your website’s domain instead of a custom URL scheme. That way, if the app doesn’t handle custom URL schemes or if your app is not installed, then at least it will take the end-user to your website. You would do this by setting the “host” part of the intent-filter as described here…
But the strange thing is that I tested it with the default browser and as a link in the default email app and none of these seems to work. I would think that when calling system.openURL(“myapp://“) it also calls the default browser to launch the app right?
When you call system.openURL(“myapp://”), then what we do is turn that URL into an Android intent and then have the Android OS launch the default activity for that URL by calling the Java Activity.startActivity() method…
The above is how you can get your app to launch another app via it’s intent-filter. If no app on the device has a matching intent-filter for that URL, then the OS defaults to the Browser app.
Now, if the app blindly passes your URL to the Java WebView.loadUrl() method on Android, then it will ignore all app intent-filters on the device and attempt to do an HTTP request to a server that doesn’t exist. In your case, you’ll get a 404 error.
Regarding the Browser not launching your app, it works for me if I use an HTML <a/> tag on my webpage.
Are you invoking your URL via JavaScript instead?
I ask because I know there is this “quirk” with Android’s WebView Java class where it’s WebViewClient.shouldOverrideUrlLoading() does not get called for URLs invoked via JavaScript… and that’s the method that most native Android developers use to override URL handling.