Handling URL scheme on Android?

Hi,

is it possible to handle URL schemas like in iOS? In iOS, you specify CFBundleURLSchemes in build.settings. I thought, that since some time, this functionality is available for Android as well? Am I mistaken?

Thanks in advance!

Best regards,
Martin

The URL scheme is an iOS only thing, but Android has something similar by using the app’s unique name, I.e com.companyname.appname.

As of the newest daily builds ( build #1138 and higher), we’ve added Android intent filter support which will allow your app to be launched via URL schemes.  It’s currently undocumented because it’s in the experimental phase.  Partly because I don’t fully understand the proper way to set up an intent filter just yet, since they’re kind of complicated on Android… nor do I have the time to experiment with it. But you’re welcome to give it a try.
 
Adding the following to your “build.settings” file will set up your app to be launched via a URL scheme from another app…

settings = { android = { intentFilters = { { label = "Optional Title Goes Here", actions = { "android.intent.action.VIEW" }, categories = { "android.intent.category.DEFAULT", "android.intent.category.BROWSABLE", }, data = { scheme = "corona" }, }, -- You can add more intent filters here. }, }, }

 
I’ve tested the above and it will launch the app via a URL such as “corona://test”.  You should change the name of the scheme for your app of course, but this should give you something to work with.
 

Google documents intent filters here…

http://developer.android.com/guide/components/intents-filters.html

http://developer.android.com/guide/topics/manifest/intent-filter-element.html

Hi,

do you have any more information on this, I seem to be unable to find how to use this. I just want to launch another app of mine if it is installed, or show the Play Store if it is not installed.

Best regards,

Martin

Hi,

thanks, that looks interestig as well. Do you already have a time-plan for the next stable version, as I’d like to avoid daily builds if possible, as we are close to release.

Best regards,
Martin

No release date has been set yet.

That said, if you want to detect if your other app is installed on Android, then check out the following forum post.

   http://forums.coronalabs.com/topic/33636-my-android-app-needs-to-check-if-another-one-of-my-apps-is-installed-on-the-device-on-ios-i-use-url-schemes/?p=174720

And in case you didn’t already know, you can show your app in the app store via the following API…

   http://docs.coronalabs.com/daily/api/library/native/showPopup.html#appstore-and-rateapp

WOOT!

I wasn’t aware that support for Android URL scheme has been added!

Thank you so much!

I think I may love you Joshua :smiley:

Cheers

Emilia

Happy to help Emilia!

I am still stuck with the latest stable build, (i.e. one build before the intent filter has been added :)), is there a way that I launch the app after I detected it is installed with the described workaround?

Best regards,
Martin

Unfortunately, I can’t think of any other way to make it work with our release version’s APIs.

The closest equivalent that I can think of is to show your app in the app store, which if already purchased, will give you the option to launch the app the end-user has already bought.  You can do this via our native.showPopup(“appStore”) API…

   http://docs.coronalabs.com/api/library/native/showPopup.html

Probably not what you want, but the next best thing that I can think of.

Hmm, thanks.

We will consider upgrading or adding the functionality after the first release. Is there already a way to handle the URL via the intent filter? How does one access the data from the caputred intent?

Thanks in advance!

Best regards,
Martin

You can capture the URL and Android intent that opened your app via:

  • The launch arguments “…” on application startup.

  • The “applicationOpen” system event when your app is resumed via an intent/url.
     
    It’s easier to describe how this works by observing the following sample code on an Android device.  The below code will create a local/scheduled notification.  When you tap on the notification in the status bar, it will launch your app with an Android intent.  The below code will print the entire contents of the launch arguments and applicationOpen event.

    – Prints all contents of a Lua table to the log. local function printTable(table, stringPrefix) if not stringPrefix then stringPrefix = “### " end if type(table) == “table” then for key, value in pairs(table) do if type(value) == “table” then print(stringPrefix … tostring(key)) print(stringPrefix … “{”) printTable(value, stringPrefix … " “) print(stringPrefix … “}”) else print(stringPrefix … tostring(key) … “: " … tostring(value)) end end end end – Prints all launch arguments local launchArguments = … if launchArguments then print(”### — Launch Arguments —”) printTable(launchArguments) end – Prints the event table when an “applicationOpen” event occurs. local function onSystemEvent(event) if event.type == “applicationOpen” then print(”### — Application Open —") printTable(event) end end Runtime:addEventListener(“system”, onSystemEvent) – Tap the screen to schedule a local notification. local function onTap(event) local settings = { body = “This is a test.” } system.scheduleNotification(1, settings) end Runtime:addEventListener(“tap”, onTap)

 
 
I hope this helps!

Thanks, I will try out.

Best regards,
Martin

The URL scheme is an iOS only thing, but Android has something similar by using the app’s unique name, I.e com.companyname.appname.

As of the newest daily builds ( build #1138 and higher), we’ve added Android intent filter support which will allow your app to be launched via URL schemes.  It’s currently undocumented because it’s in the experimental phase.  Partly because I don’t fully understand the proper way to set up an intent filter just yet, since they’re kind of complicated on Android… nor do I have the time to experiment with it. But you’re welcome to give it a try.
 
Adding the following to your “build.settings” file will set up your app to be launched via a URL scheme from another app…

settings = { android = { intentFilters = { { label = "Optional Title Goes Here", actions = { "android.intent.action.VIEW" }, categories = { "android.intent.category.DEFAULT", "android.intent.category.BROWSABLE", }, data = { scheme = "corona" }, }, -- You can add more intent filters here. }, }, }

 
I’ve tested the above and it will launch the app via a URL such as “corona://test”.  You should change the name of the scheme for your app of course, but this should give you something to work with.
 

Google documents intent filters here…

http://developer.android.com/guide/components/intents-filters.html

http://developer.android.com/guide/topics/manifest/intent-filter-element.html

Hi,

do you have any more information on this, I seem to be unable to find how to use this. I just want to launch another app of mine if it is installed, or show the Play Store if it is not installed.

Best regards,

Martin

Hi,

thanks, that looks interestig as well. Do you already have a time-plan for the next stable version, as I’d like to avoid daily builds if possible, as we are close to release.

Best regards,
Martin

No release date has been set yet.

That said, if you want to detect if your other app is installed on Android, then check out the following forum post.

   http://forums.coronalabs.com/topic/33636-my-android-app-needs-to-check-if-another-one-of-my-apps-is-installed-on-the-device-on-ios-i-use-url-schemes/?p=174720

And in case you didn’t already know, you can show your app in the app store via the following API…

   http://docs.coronalabs.com/daily/api/library/native/showPopup.html#appstore-and-rateapp

WOOT!

I wasn’t aware that support for Android URL scheme has been added!

Thank you so much!

I think I may love you Joshua :smiley:

Cheers

Emilia

Happy to help Emilia!