I always find it interesting to watch the 4x100m Sprint Relay at the Olympics and Track and Field Championships. It’s the fastest and most technically difficult of all the relays. Demonstrating true synergy, a well executed relay transports the baton around the track faster than the sum of the individual personal best 100m times.
Android applications expose their Activities and related Intents-Filters through the AndroidManifest.xml, and Activities implicitly or explicitly set to exportable can be used by other applications. HP iPrintPhoto for instance invites other applications to use its PRINT Action, by declaring the following Activity in its AndroidManifest:
<activity android:name=".photo.PrintPhotoActivity" android:exported="true" android:enabled="true"> <intent-filter> <action android:name="org.androidprinting.intent.action.PRINT"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="image/*"/> </intent-filter> .. </activity>
Application that like to use the image printing feature provided by iPrint Photo, would create and new Intent and start the print Activity, like so:
Intent intent = new Intent("org.androidprinting.intent.action.PRINT") .addCategory(Intent.CATEGORY_DEFAULT) .setDataAndType(uri,"image/*"); startActivity( intent );
The example above assumed that an Uri to an image already existed. If that’s not the case, and for instance the content of a Canvas needed to be printed, then the Uri could easily be created on the fly:
Bitmap mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); Canvas mCanvas = new Canvas(mBitmap); String filename = String.valueOf(System.currentTimeMillis()); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, filename); values.put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis()); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri= getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values); OutputStream outStream = getContentResolver().openOutputStream(uri); bmp.compress(Bitmap.CompressFormat.JPEG, 90, outStream); outStream.flush(); outStream.close(); Intent intent = new Intent("org.androidprinting.intent.action.PRINT") .addCategory(Intent.CATEGORY_DEFAULT) .setDataAndType(uri,"image/*"); startActivity( intent );