Mission: In this lab, you will learn how to open a device’s other native apps from inside another app. You will also learn how to make your app be able to be opened from within another app.
Specification: You will create an app that will be able to open other apps such as maps, youtube, and sms. You will then make another app that will open your first app.
Create a new Alloy mobile project inside Titanium Studio. In the index view, create five buttons with the labels, Open Maps, Open SMS, Open Dialer, Open YouTube, and Open App Store / Market.
In the index controller, add a click event listener for each of these buttons. Then use the Ti.Platform.openURL() function to open a corresponding url for each of these tasks. These urls are:
Maps: use maps:// or http:// as the URL scheme for iOS & Android respectively. Use this as the map location: maps.google.com/maps?q=440+Bernardo+Ave,+Mountain+View,+CA&hl=en&sll=42.746632,-75.770041&sspn=6.364676,10.305176&oq=44&hnear=440+Bernardo+Ave,+Mountain+View,+Santa+Clara,+California+94043&t=m&z=17
SMS: use sms:+ and a number of your choice
Phone: use tel:// and a number of your choice
YouTube: use http://www.youtube.com/watch?v=iodEa0eitag as the target URL
Store: for iOS, use http://itunes.apple.com/us/app/legoland-california-official/id452395530?mt=8 and for Android use market://details?id=com.zc.android
Build your application and test that these buttons perform their assigned functions.
Now we will modify this app so it can be opened by the second app.
For iOS, add the following code to the tiapp.xml file, and make sure the app ID matches the app ID you chose for your app.
For Android: you must have built for the emulator at least once, the follow these steps:
Copy the <application> tag and all its contents
In tiapp.xml, modify the <android> tag to remove the '/' that makes it an empty tag; add a closing </android> tag
Within that tag, add <manifest></manifest> tags
Within the manifest tags, paste the tags you copied from the generated manifest
Following the </intent-filter> closing tag, add the following code:
To work around a tooling default, we'll need to build the project from the command line with an additional flag. First, clean the project in Studio. Then, open a terminal window and navigate to your project's root directory. Enter the following command (make sure to specify the appropriate target platform, though):
titanium build --platform ios --force-copy
Create a second Alloy app with a name and app ID of your choice. The app should have three buttons in its index view. They should have the labels: “Open Target app”, “In Target app, open Maps”, and “In Target app, open YouTube”. Give these buttons the action properties of “”, “maps”, and “youtube” respectively. Also, give all the buttons the onClick property of “doClick”
In the index controller insert the following doClick function before opening the window:
Build and run the application with the command line technique described above. Once the app is open, you can press the Open Target App button, and your first app should open.
Close the app, and we will now edit our first app to accept arguments when it is called to be opened.
In the URLSchemes app, add the following code to the alloy.js file:
Now, in the index controller add the following code to the beginning of the file:
Build both app as you did before, and now if you click any of the buttons in the second app we made, the described action should be taken by the first app.
You can download the completed applications from: this link.