I’ve been watching some other blog posts about building Smartphone camera apps for Android, seeing all of the UI design work required and the lines of code needed. While I always want to learn more about Smartphone APIs for Android and iOS, I also care a lot about getting applications built quickly with as few lines of code as possible that work with Android and iOS. On the Embarcadero RAD Studio XE5 DocWiki and in a YouTube video we show developers how to build a Smartphone Camera App that lets you take pictures, preview them, save them to your camera roll and also share the image with other apps. Start with a blank app template project, add 6components (TToolBar, TImage, TActionList and 3 TButtons), set a few property values int he Object Inspector, choose 3 predefined actions (TTakePhotoFromLibraryAction, TTakePhotoFromCameraAction and TShowShareSheetAction), associate the 3 actions to each of the three buttons, connect the action execution for each button to create event handlers for each action and finally write 3 lines of code (one per action event). Select Target Platform for iOS and Android and choose Build and you have finished camera apps for iOS and Android.
The 3 lines of code for the three action event handlers:
procedure TForm1.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap); begin Image1.Bitmap.Assign(Image); end; procedure TForm1.TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap); begin Image1.Bitmap.Assign(Image); end; procedure TForm1.ShowShareSheetAction1BeforeExecute(Sender: TObject); begin ShowShareSheetAction1.Bitmap.Assign(Image1.Bitmap); end;
The Mobile Tutorial, "Taking and Sharing a Picture (iOS and Android)" can be found at http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Taking_and_Sharing_a_Picture_(iOS_and_Android)
The Mobile Share Sheet with Delphi XE5 video can be found at http://www.youtube.com/watch?v=JS6o4RgDX1g
A couple of additional notes about Camera apps and sharing images:
- iOS Share Sheet functionality first appeared in version 5 and was enhanced by Apple in iOS 6
- Android ShareActionProvider is available starting with Android API Level 14 and higher
- TShowShareSheetAction is part of the FMX MediaLibrary - http://docwiki.embarcadero.com/Libraries/XE5/en/FMX.MediaLibrary.Actions.TShowShareSheetAction
- Make sure to check Project | Options | Uses Permissions - for Android make sure the Camera setting is set to true (by default we set this True in debug and release configurations, you can change all permission options for the defaults you want for debug and release configurations).
You can get started now by downloading the RAD Studio XE5 trial at http://www.embarcadero.com/products/rad-studio/downloads