How to create a Sony Xperia™ Z1 camera app using the Camera Add-on API

If you’re both a developer of camera apps and a fan of the recently-announced, camera-centric Sony Xperia Z1, check out this Camera Add-on API tutorial, which will show you how to integrate your camera app with the Xperia™ Z1 using the Camera Add-on API. Read on to discover how to easily take advantage of the Camera Add-on API, and make it easier for your users to quickly launch and utilise your camera app for more frequent use.

When you launch the Xperia™ Z1 camera and press the Camera Apps mode selector button, you’ll find an array of intelligent camera apps – Info-eye™, Social live, Timeshift burst, and AR effect. For those users who have installed your camera app on Xperia™ Z1, the Camera Add-on API allows you to display your camera app alongside the Xperia™ Z1 camera apps. The Camera Add-on API is included as part of the Sony Add-on SDK 2.0. This API provides two ways to extend your app to the Sony Xperia™ Z1:

  • Your app can be launched as a Mode in the Camera Apps mode selector from the Xperia™ Z1’s camera app.
  • The Camera Apps mode selector of the Xperia™ Z1’s camera can be launched from your own camera app.
Camera Apps mode selector button (left), which launches available camera apps (right).

Camera Apps mode selector button (left), which launches available camera apps (right).

Getting started with the Camera Add-on API
The basic parts of the Camera Add -on API–based camera app include a Mode selector button, a click listener, and a Mode.xml file.  The Mode selector button is the button on the Xperia™ camera app used to launch the camera’s modes. The click listener is used to catch the button click event. The Mode.xml file provides the configuration parameters of your camera app.

After you’ve installed the Sony Add-on SDK 2.0, to integrate the Camera Add-on API functionality into your existing camera app, follow the steps below:

1. Add a visible Mode selector button to your Xperia™ camera app, as shown by the following example:

mButton = ((ImageButton)findViewById(;
mButton.setOnClickListener(new ButtonClickListener());

2. Once you have created the Mode selector button, add a click listener that opens the Mode selector. Make sure to catch the clicks, as they will be used to trigger the Mode selector to appear. The following example shows how to implement a click listener to handle this:

private class ButtonClickListener implements View.OnClickListener {
     public void onClick(View v) {

3. Create a mode.xml file in the xml folder of your Android project. In order for the Camera Add-on framework to have sufficient information about your Xperia™ camera app, you will need the mode.xml. The following example shows how you can add the mode information:

     selectorLabel="@string/mode_selector_label" descriptionLabel="@string/mode_description_label">

4. Update the AndroidManifest.xml by adding the following permission:

<uses-permission android:name="com.sonymobile.permission.CAMERA_ADDON"></uses-permission>

Add a link to the mode.xml file created in Step 2.

<action android:name=""></action>
<meta-data android:name="" android:resource="@xml/ mode">

Then add the following uses-library:

<!--  android:required="false"|"true" is an implementation choice. <b> </b> -->
<!-- Put "true" if you only want the APK to be installed on Xperia devices containing the library; "false" otherwise. -->
<uses-library android:required="”false”/" android:name=""></uses-library>

It is also required that you declare the following in the AndroidManifest.xml:


5. Implement error handling. In order to avoid force close when the Camera Add-on framework is not supported, check for existence of the framework and run appropriate code based on the result, like in the code example below. This means you will only need a single apk to support all compatible Android devices, whether they support the camera framework or not.

protected void onResume() {
   // Set a button to open CapturingModeSelector.</em>
   // User can launch any mode of all camera add-on applications,
   // including modes of SOMC
   // camera application, by clicking a mode icon which is listed on
   // CapturingModeSelecotor.
   // At first, create a parent view for capturing mode selector view.
   ViewGroup modeSelectorContainer =
   // Create CapturingModeSelector.
   try {
     mCapturingModeSelector = new CapturingModeSelector(this, modeSelectorContainer);
   } catch (NoClassDefFoundError e) {
     // If class is not found (Camera Add-on API not supported),
     // implement suitable exception handling.
     Log.e("CAMERAADDON", "Camera add-on library not found. Handle the exception,"
          + "eg. finish the activity.");
   if (mCapturingModeSelector != null) {
     // Set two listeners.
     mCapturingModeSelector.setOnModeSelectListener(new MyOnModeSelectListener());
     mCapturingModeSelector.setOnModeFinishListener(new MyOnModeFinishListener());
     // Show a button to start mode selector.
   } else {
     // If Camera Add-on API is not supported,
     // capturing mode button should not be shown.

Once you’ve incorporated the Camera Add-on API into your Xperia™ camera app, you can test it with the Xperia Cam Modes application included as part of the Sony Add-on SDK. The Xperia™ Cam Modes application enables you to develop and test Camera Add-on apps on AVD (Android Virtual Device). It provides a simplified user interface and a button to open the Mode selector.  Additional information on the Xperia Cam Modes application is available in the How to use the Camera Add-on API guide included with the Sony Add-on SDK  documentation package.

Note: If you want to create a new Xperia™ camera app, please review the Camera Add-on API code examples included in the Sony Add-on SDK, and then use it as a reference for your app development.

Get more visibility – apply for the Stand out app search campaign
During 2013, Sony is running a new version of our Stand out from the crowd campaign, where we are searching for professional developers, with high quality apps that can bring something extra to the Sony experience. In return, we can offer the best developers support, hardware, and promotion online and at major industry events.

If you’ve got a great idea – and the ability to make it real – you could have what it takes. Apply to join the Stand out from the crowd app search campaign now!


We hope this gives you all the info you need to incorporate the Camera Add-on functionality into your existing camera app. If you have any questions, feel free to leave us a message in the Comments field below, and we’ll get back to you as soon as possible!

More information

Add a comment +

Sort by: Newest | Oldest | Most popular

No comments so far.