From the File menu select New > Project....

New Project menu

The New Project wizard is displayed. Select iDigi Android Project within the Android folder and click Next to start the wizard.

Wizard selection window

Enter a name for your project into the Project name field, for example HandleDoCommand. Then, select the Android API Level (version) to use for the project.

iDigi Android application project wizard

Warning

The name of the project must be unique in the workspace. If there is already a project with the same name inside the workspace, the wizard displays a message and will not continue until a different name is used.

Optionally you can also change the Package name and Activity name for the project.

Click Finish to create the project.

When the project is created, it is displayed in the Package Explorer view. Expand it to see its contents.

Package Explorer

Open the main activity file of the project to start editing it. The file is located under the src/<package name> folder of the project.

Package Explorer - Main activity file

Double-click the file to open it in the main editor.

Main activity file

Replace the following lines:

Host session

// TODO: write your application code here:
// ---------------------------------------
// Use iDigiServiceManager.sendTextFile("path/filename", "filedata") to
// upload a text file (*.txt, *.xml, etc) to iDigi with the given contents.
// ---------------------------------------
// Use iDigiServiceManager.sendFile("path/filename", "localpath") to
// upload any local file to iDigi.
// ---------------------------------------
// Use iDigiServiceManager.subscribeDoCommand("target", this) to
// listen for do_commands of the specified target.


With this one:

Host session

iDigiServiceManager.subscribeDoCommand("myTarget", this);


This line of code tells the application to listen for do_commands which have the myTarget string as a target (command identifier). Whenever a do_command having the target myTarget is sent to the Android device, the application will execute the commandReceived() callback.

Replace the following lines:

Host session

// TODO: Write here the code you want to execute when a
// do_command of the registered target is received.
//
// The string returned by this method will be sent to iDigi as
// the answer of the do_command.
return "answer";


With these ones:

Host session

Toast.makeText(this,"do_command received: " + data.trim(),Toast.LENGTH_LONG).show();
return "do_command received";


The first line is the code that is executed when a do_command with the target myTarget is sent to the Android device. It displays a pop-up with the data of the do_command. The second line returns the text that will be sent back to iDigi to indicate that the do_command has been received successfully.

Notice that you will need to import the toast control in order to display the toast (pop-up) message. To do so, write the following line in the imports section of the application code.

Host session

import android.widget.Toast;


The file should now appear as follows:

Main activity file - Modified

Save the file and build the project. To do so, select the project from the Package Explorer view, right-click on it and select the Build Project option from the context menu.

Build the project

If you are working in Linux, you will need to kill the current process and then start it as root. If you already did it or you are working in Windows, you can continue with the launch process, otherwise follow these steps:

  1. Open a shell console and kill the current process by executing the following command:

    Host session

    /<android_sdk_location>/platform-tools/adb kill-server


    Where <android_sdk_location> is the path where the Android is installed.

  2. Restart the process by issuing this command:

    Host session

    sudo /<android_sdk_location>/platform-tools/adb start-server


    Where <android_sdk_location> is the path where the Android is installed.

  3. To verify that you are the owner of the instead of Eclipse, you should see the following output in the shell:

    Host session

    * daemon not running. starting it now on port 5037 *
    * daemon started successfully *


    If you don't see that output, you should repeat steps 1 and 2.

The last step in the process is to launch the iDigi project. To do so, select the project from the Package Explorer view, right click on it and select the Run As > Android Application option from the context menu.

Tip

In the future, you can launch your project by clicking the Run button from the main toolbar.

Run button


This action will launch the iDigi Android application in your Android device. Depending on your Android device type, the process will behave differently:

The launch process takes a while to complete; it will display its progress in the Console view:

Console progress

Once the application is launched, the Android device will display its main activity:

HandleCommand - Main activity

It is very important that the iDigi Connector for Android is running before you launch the application. You will know that it is running if the iDigi logo is displayed in the status bar. If iDigi was already running before you launched the application, you can continue with the next step, .

In this case, the service was not running as the logo is not displayed, so it is necessary to start the iDigi Connector for Android and execute the application again. To do so follow these steps:

  1. Go to the applications menu and execute the iDigi for Android application.

    Applications menu

  2. Activate the Connector for Android by pressing the Activate iDigi option.

    Start iDigi Connector for Android

  3. Return to the applications menu and execute your HandleDoCommand application.

    Applications menu - HandleCommand

  4. Notice that the iDigi logo is visible, meaning that the iDigi Connector for Android is running.

    HandleCommand - iDigi running

Clock


Prev. Step

Home

Next Step