Abstract

Last Updated: April 17, 2014

Starting from firmware version 2.31 the YotaPhone SDK is available for developers to develop their own apps.The article contains step by step manual on how to create a project and build applications for YotaPhone as well as main components of development environment.The article is intended for third–party developers of back screen applications.

Getting Started

Before you start with creating your first back screen application, be sure you have already set up:

  • Android SDK
  • Android API 17
  • YotaPhone SDK
  • Eclipse IDE (optionally)

Eclipse is used here as an example but you can use any other capable IDE.If you have no Android platform development experience you can try out this class before.

Creating a Project and Building the Application

1. To create an Android project:

  • Click File -> New -> Android application project Fill the text fields and select API 17 in related dropboxes, as on the picture below:

images

image

  • Check Create Activity checkbox as above

image

  • Click on Finish button. The project has been created.

2. Import yotaphone_sdk library:

  • Go to project properties to specify dependency of the yotaphone_sdk library. Right click on the project->Properties->Java Build Path->Add External JARs… and select com.yotadevices.yotaphone.sdk.1.0.jar from the list in dialog. You can find it in <sdk>/add-ons/addon-yotaphone/libs folder (first you should download the emulator. See Download and install Yotaphone SDK)

image

3. Set up Manifest

To work with back screen you should implement some fixes in the AndroidManifest.xml. Open it and add the following:

<!-- Icon which is visible in the backscreen launcher -->
<meta-data
    android:name="com.yotadevices.BS_ICON"
    android:resource="@drawable/icon_for_backscreen" />

<!-- Title which is visible in the backscreen launcher -->
<meta-data
    android:name="com.yotadevices.BS_TITLE"
    android:resource="@string/app_name" />

<!-- Permission for working with backscreen -->
<uses-permission
    android:name="com.yotadevices.framework.permission.ACCESS_BACKSCREEN" />

<!-- Library for working with backscreen -->
<uses-library
    android:name="com.yotadevices.yotaphone.sdk.1.0" />

Note: If you want that your application works only on the YotaPhone, you should add required="true" flag in <uses-library/> tag.

4. Creating Backscreen Service

Let’s create a service for work with the back screen. Create service HelloWorldOnBackscreen with following content:

public class HelloWorldOnBackscreen extends BSActivity {
    public HelloWorldOnBackscreen() {
        super();
    }

    @Override
    protected void onBSCreate() {
        super.onBSCreate();
    }

    @Override
    protected void onBSResume() {
        super.onBSResume();

        LayoutInflater inflater = LayoutInflater.from(getContext());
        View view = inflater.inflate(R.layout.helloworld, null, false);
        getBSDrawer().drawBitmap(view, Waveform.WAVEFORM_GC_FULL);
    }

    @Override
    protected void onBSStop() {
        super.onBSStop();
    }
}

On onBSResume method the application is ready to draw on back screen. Inflate layout and put it on back screen. The following is our helloworld layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@android:color/white" >

    <EditText
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@android:color/black"
        android:text="Hello world from backscreen" >
    </EditText>

</LinearLayout>

HelloWorldOnBackscreen class extends BSActivity class which is just an android service. That’s why it shall be specified in the manifest file. Add the following to the manifest file:

<!-- Service for working with backscreen -->
<service
    android:name="com.example.backscreenfirstapp.HelloWorldOnBackscreen"
    android:exported="false" />

The AndroidManifest.xml should be like the following now:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.backscreenfirstapp"
        android:versionCode="1"
        android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="17" />

    <!-- Permission for working with backscreen -->
    <uses-permission
        android:name="com.yotadevices.framework.permission.ACCESS_BACKSCREEN" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.backscreenfirstapp.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <!-- Service for working with backscreen -->
    <service
        android:name="com.example.backscreenfirstapp.HelloWorldOnBackscreen"
        android:exported="false" />

    <!-- Library for working with backscreen -->
    <uses-library
        android:name="com.yotadevices.yotaphone.sdk.1.0"
        android:required="true" />
    </application>
</manifest>

The back screen service is ready now. We can start it from our MainActivity:

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
    Intent i = new Intent(this, HelloWorldOnBackscreen.class);
    startService(i);

    super.onResume();
    }
}

This is the end of the class. Run your application Run->Run. It should print Hello world from backscreen on the back screen.