Using “Intent Filters” is a very powerful way to connect different applications together which allows greater reuse and makes a user experience transparent to the fact that more than one application is used to achieve a certain task.
Here is an example that is discussed in “A Beginner’s Guide to Android” Google I/O 2010 talk.
Let’s say there is an application that finds hotels and would like to use another application to book it. For that it creates an implicit “Intent” where it says: “hey android, I intent to book this hotel, please find an application that is capable of booking it, and pass the data to do the booking”:
String action = "com.hotelapp.ACTION_BOOK"; String hotel = "hotel://name/" + selectedHotelName; Uri data = Uri.parse( hotel ); Intent bookingIntent = new Intent( action, data ); startActivityForResult( bookingIntent );
Now let’s say there is such a booking app installed on a device. Then, in its manifest, it will announce itself through the “intent-filter”, as an application capable to perform this action, e.g. “com.hotelapp.ACTION_BOOK”, to get the data from another app and book a hotel:
<activity android:name="Booking" android:label="Book"> <intent-filter> <action android:name="com.hotelapp.ACTION_BOOK"/> <activity android:scheme="hotel" android:host="name"/> </intent-filter> </activity>
Within the “Activity” of a booking app, you can then “getIntent()” to find the one that was used, get the action along with the data and do the booking:
@Override public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstance ); setContentView( r.layout.main ); Intent intent = getIntent(); String action = intent.getAction(); Uri data = intent.getData(); String hotelName = data.getPath(); // Providing booking functionality // ... ... setResult( RESULT_OK, null ); finish(); }
THE TAKE AWAY: Think about exposing functionality ( can be full of partial workflows ) of your apps in order for other developers / apps to use. At the same time check what is already exposed for you to leverage from other developers / apps.
P.S. Read more about Intents and Intent Filters
Thanks for sharing the tutorial, it was very helpful to me as I am new to Android application development
Your explanation is good at intent-filters, a quick process of learing real time usage Thanks.
I hope to see more on this blog like above
Thanks for the Android tutorial – very helpful for anyone interested in developing Android applications
Definitely incredibly helpful. Nice of you to share this Android App development guide for free
thanks for this example.. i wanted to use the database content of my other app .. creating a custom intent filter will solve this..