Android Photo Booth app II

30 Apr

This tutorial demonstrates how to develop an Android Photo Booth app. You’ll build an app that let’s you take pictures, assign pictures to canvas and share picture via email. When pictures are taken, then will display in one of 4 canvases. When all canvases have assigned pictures, it will rotate back to first canvas.

What You’ll Build

  • You’ll build a photo booth app allowing you to:
  • Take pictures using camera
  • Save pictures onto canvas
  • Display 4 pictures on 4 different canvases
  • Select a canvas picture
  • Share a canvas picture.

The completed app will look like the figure below:


Before starting

Make sure your computer and your phone are set up to use App Inventor. Start a new project in the Designer window, and name it “PhotoBooth”. When in Editor, click Connect to Phone, and make sure the phone has started the App Inventor app.

Placing the Initial Components

In Designer Editor, click on the Layout category to view all the App Inventor layout components. Once expanded, select HorizontalArrangement layout and drop onto designer viewer. From the properties panel set the Width of this layout to “Fill parent”.

Next, from “User Interface” drawer, select and drop three buttons into this layout and setting their properties as follows:

The completed arrangement should look like figure below:


Select and drop another HorizontalArrangment component below HorizontalArrangement1. Select components as shown below and set their properties as indicated:


This arrangement should look like figure below:


Select and drop another HorizontalArrangment component below HorizontalArrangement2. Select components as shown below and set their properties as indicated:


This arrangement should look like figure below:


Select and drop a TextBox component below HorizontalArrangment3. Select and drop Button below this TextBox and set their properties as below:


This arrangement should look like figure below:


Finally, we will need 3 non-visible components as shown below.

  • Camera –  Media drawer – used to take picture – Sensor
  • Notifier – User Interface drawer – to display informative information
  • Sharing -Social drawer – to share image via email


Adding Behaviors to Components

You have added Button, Canvas, TextBox and non-visible components. Its now time to define how the components behave.

Adding the Click event to btnHelp Button component

This button is used to display help information using Notifier component. Once this button is tapped, we will display usage-information. Since our help-text is long, we use a “join” block (Text drawer) to join our help-text. Note that “join” has a mutator icon, meaning that its shape can expand or shrink.


Taking picture and saving picture into Canvas component

User will be able to click on btnTakePicture button or the btnCamera button to start invoking the internal camera app of the device. There are 4 canvas components on the screen layout and they are named Canvas1 through Canvas4. Each time a picture is taken, we will set the background of one of the canvas components onto the new picture. The 1st picture will be set as background of Canvas1 and 2nd picture will be set as background of Canvas2 and etc. This will continue through for all four canvas components and will then rotate back to 1st canvas. To keep track of which canvas should be used, we use a global variable which will be incremented for every time a picture is taken.

Initializing global variable: From the Built-in Variables drawer, select “initialize global name to” block. Change its name to canvasNum. Next, from Math drawer select “0” number block and plug into socket of the new variable block.


Starting the camera: When either btnTakePicture or btnCamera buttons are clicked, we will use their associated Click event handler to capture the event and start the camera using Camera1.TakePicture block:


Saving picture as canvas background: After a picture is taken AND accepted, the Camera.AfterPicture will be triggered. In this event, the global variable canvasNum will be incremented by 1. This will allow us to rotate the canvas and save, as background, to Canvas1 through Canvas4. When canvasNum is over 4, we rotate it back to 1 so that we can save the picture back to Canvas1 background. To keep the code modularized, we use a procedure that can accept an argument (the full image path of the just-taken picture).

Using the Built-in Procedures drawer, select “Procedure” block and add into blocks-editor viewer. The procedure is a mutator block. Figure below shows how to use mutator and updates that are needed for the procedure.


The blocks in the procedure will need to inspect value of our global index, canvasNum. If this value is 1, then we set the passed in image (path) as background of Canvas1, if canvasNum is 2, we set it as background of Canvas2, and so on. For purpose of this tutorial, we will use if-then-else block. The completed code will look like figure below:


The setPictureToCanvas procedure will need to be invoked after a picture is taken (Camera1.AfterPicture). In this handler, we increment our global variable “canvasNum” by 1.


Next, we inspect if the resulting value is greater than 4. If so, we set it back to 1.


The Camera.AfterPicture event handler passes a parameter called “image” which is the full path of the picture that was just taken. Knowing this, we invoke our “setPictureToCanvas” procedure passing this “image” parameter to it. The full block-code for Camera1.AfterPicture is shown in figure below:


At this time, every time a picture is taken, it will display in Canvas1, then Canvas2, then Canvas3, then Canvas4 and back to will reset back to Canvas1.

Sharing pictures:  At this time, we want to allow user to share a picture by selecting it (via tapping on a canvas) and then sharing it by tapping on the “Share Picture” button. To capture the canvas touch events, we use Canvas.Touched event handler. This event handler is triggered every time the canvas is touched. Canvas also includes a block property called Canvas.BackgroundImage which returns the full image-path of the image that is assigned to its background. At this time we retrieve the image-path and display it in our TextBox (txtPictureToShare):


The completed block-code for handling the touch events on all 4 canvas are shown in figure below. Note that the code for all 4 canvas are same with exception of canvas name:


The final functionality to implement is to share the picture via Sharing component. When btnSharePicture is clicked, we need to validate if a valid picture was selected. A valid picture would mean that its full-path starts-with “file:///”. For this, we use the “contains” block in the Built-in Text drawer. If the path includes “file:///”, then we use “Sharing.ShareFileWithMessage” block and pass it the full image path and message-body. If the path is invalid (doesn’t include “file:///”), we display an alert message using “Notifier.ShowAlert” block.


1 Comment

Posted by on April 30, 2015 in Uncategorized


One response to “Android Photo Booth app II

  1. Mo

    May 1, 2015 at 9:17 am

    Yes, i like it.👍any ideas for uploading images to cloudstorage?there are enough possibilities ill think,what about selfcreated postcards and upload to printservice for postcard services.
    Do you have exp in WebOs for LG TV?Let me know,cause LG Tv’s are disconnected from Facebook/Twitter/Picasa i just read it last nicht.Would be the right Moment to dev a WebOs APP to connect to API of that social provider,do you think im right?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: