This documentation relates to previous versions of Titanium.

To see the latest documentation, visit docs.appcelerator.com.

Skip to end of metadata
Go to start of metadata

Android Intent Filters give Appcelerator apps the ability to receive Intents from other Android applications. If you are an Android device user, you're probably familiar with the SEND Intent. It's the one that pops up a "Share via" list of apps when you attempt to share links, pictures, videos, etc...

Here we are going to create a very simple app that will make itself available to a very specific Intent via Android Intent Filters. The app will present itself in the Intent list anytime we click on a link that is destined to http://www.appcelerator.com. This app was inspired by a Q&A entry that requested this exact behavior.

Let's first look at the code for our app. We're simply going to display a label to the user that tells them we know they just clicked on a link to www.appcelerator.com. Nothing fancy here.

app.js

If you build and run it, your output should look roughly like this:

Custom AndroidManifest.xml

In order for our Appcelerator app to leverage Intent Filter functionality, we need to make a few changes to our AndroidManifest.xml. As you may or may not know, unless you define a custom AndroidManifest.xml file for your project, Titanium Studio will generate a new one for you on each build. Here's how you create a persistent manifest that you can manage yourself.

  1. Create a default mobile project in Titanium Studio.
  2. Replace the existing app.js code with the code above.
  3. Build and run your app on either an Android device or emulator.
  4. In your project's root directory create a platform/android directory
  5. Go to your project's build/android directory and copy AndroidManifest.xml
  6. Paste the AndroidManifest.xml into your newly create platform/android directory

In the end, your project structure in Titanium Studio should look something like this:

OK, now you have a custom AndroidManifest.xml that will persist between builds. We can now make the necessary changes to allow it to receive Intents from other Android apps.

Open up your custom AndroidManifest.xml and find the main activity for your app. It should be directly under the <!-- TI_APPLICATION --> comment. As you can see, it already includes an Intent Filter for launching the app. We are going to add one more to handle links to http://www.appcelerator.com.

AndroidManifest.xml

Very briefly, the data subelement tells the intent-filter that we are handling for HTTP requests targeted at the host www.appcelerator.com. The 2 category subelements tell Android that we want to receive implicit Intents and that they can come from the browser, respectively. Finally, action states that we will be handling VIEW intents. For more information on the specifics of Intents and Intent Filters, be sure to check the Android developer documentation on the subject.

You now have an app that is ready to receive Intents. Install it on either an Android device or emulator and make sure it runs. Now you can test the Intent Filter by doing the following:

  1. Open your Android browser
  2. Search for "appcelerator" on google.com
  3. Click the link for http://www.appcelerator.com

You should be greeted with an Intent list that looks something like this:

Select your app in the list and you will then be directed to your app containing the "I'll bet you just clicked on a link to www.appcelerator.com" label.

Sample Project

Download the full Intent Filter Test project at the Appcelerator Documentation Examples Github repository

Android Dev Guide: Intents and Intent Filters