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 embedded 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 embedded 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

Before launching the application in the embedded device, you must ensure it is connected with the . To do so, click the Device Manager button from the Workbench's main toolbar:

Open Device Manager

Select the configuration you created previously. If the Debug Connection Status displays Disconnected, click the Connect button.

Open Device Manager

Once the device is connected with the , you can close the dialog and continue with the launch process.

Open Device Manager

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 transfer and launch the iDigi Android application in your embedded device. Once the application is launched, the embedded 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