IR remote sensor

Create IR remote-enabled apps for Xperia™ Tablet S [code]

Yesterday, we published the Sony add-on SDK on Developer World, and today, we thought we should highlight how you can create new innovative IR remote use cases for your app on the Xperia™ Tablet S, such as an app that could switch the channels on TV, based on specific genres (sitcoms) or interests (sports). Or that you can create a new app, such as a cool TV remote, using the IR remote functionality of the Xperia™ Tablet S. With the open sourced IR remote sensor API for the Xperia™ Tablet S, all this is possible. Read on to learn more and download the IR remote sensor code examples and documentation kit.

One of the features of the Xperia™ Tablet S is the universal infrared (IR) remote control app that can control devices such as HDTVs, DVD players, audio systems, and cable boxes. And for developers, there is an IR remote API available in the Sony Tablet SDK Add-on to transmit remote control commands.

For users, a macro function is also available to let the user create personalised shortcuts and execute sequenced commands. For example, the user can create a “Watch TV” macro for a “Watch TV” button that can execute an IR remote command to first power up the cable box, turn on the TV, and activate the stereo system.

remote_control_app_running_on_XperiaTabletS

The remote control app running on Xperia™ Tablet S.

You could even imagine having a tablet app that could switch the channels on TV, based on specific genres (sitcoms) or interests (sports). Or, consider a tablet app with a time-based user preference setting for watching favourite channels at specific times.

Whatever the use case may be, as a developer, you have the possibility to create your own tablet apps that can send IR signals to any IR-based entertainment device. And to help you understand what commands are being sent from the tablet to an IR-enabled device, you can use the IR remote sensor code examples and documentation kit.

IRremoteoverview

Overview of the IR Remote Control app and API.

How the Sony IR remote sensor API works
The Sony add-on SDK provides the IR remote API to transmit remote control commands. The API set is a subset of functionalities embedded on Sony’s IR Remote Control application. The diagram above illustrates how an app accesses the Sony remote Control API. If you create an app, it will have the same access as the Sony Remote Control app on the tablet, through the IR remote API, without the need for low level communication with the infrared element.

How to create an IR remote-enabled app
In order to create an IR Remote enabled app, you will need to make the Android framework recognise your app as an IR remote-enabled app. To do so, declare your app in the AndroidManifest.xml in the following way:

  1. Add the following “uses-permission” (mandatory)
<uses-permission android:name="com.sony.remotecontrol.permission.API"/>
  1. Add the following “uses-library” (mandatory, but see exception below)
<uses-library android:name="com.sony.remotecontrol.ir.v1" />

After creating the example project based on the IR Remote Demo, the Android manifest should look like this:

<manifest xmlns:android="<a href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>" package="com.example.sony.nfx.irremote" android:versionCode="1" android:versionName="1.0">

<uses-permission android:name="com.sony.remotecontrol.permission.API" />

<uses-sdk android:minSdkVersion="15" />

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">

<uses-library android:name="com.sony.remotecontrol.ir.v1" />

<activity android:name=".DeviceListActivity" android:label="@string/app_name">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity android:name=".RemoteActivity" android:label="@string/app_name" />

<activity android:name=".DeviceObserverActivity" android:label="@string/app_name" />

</application>

</manifest>

Exception when using the IR remote sensor API in an existing app
An IR Remote sensor API-based application can be part of an existing application. If you want to support the IR remote Sensor API in your current application, here is what you need to do. In the Android Manifest, add the following line:

<uses-library android:name="com.sony.remotecontrol.ir.v1" required=false/>

This ensures the library is not used to filter out your application for devices which do not support it. Then you can dynamically check for the class by using the code below in your launcher activity or in a separate class.

String checkLibrary = "com.sony.remotecontrol.ir.v1";
   try {
       Class libraryToInvestigate = Class.forName(checkLibrary);
       // Dynamically initiate the library
        // Initiate constructor or methods
   } catch (ClassNotFoundException e) {
       // If class is not found (IR Sensor API not supported), handle exception and use a home widget or normal activity as fallback
   } catch (Exception e) {
       // Unknown exception
  }

For additional reference, we recommend that you take a look at the excellent Android SDK tutorials on Mobiletuts+, such as using reflection in Java, and how to work with the uses-library in the Android Manifest.

Download the Sony add-on SDK and get started right away!
To access the IR remote sensor API, start by installing the Sony add-on SDK. Then we recommend you to download the IR remote sensor code examples and documentation package which includes an an overview of the IR remote sensor, along with a code example and API references. Feel free to download and get started right away!

More information

Comments 8

Sort by: Newest | Oldest | Most popular

1-8 of 8 comments.