This tutorial demonstrates how to develop and launch your first Android application in the device. The application allows you to blink a device LED on and off.

Before creating your project, make sure your device is correctly connected, powered, and running. Once your device is ready for development, follow these steps:

Step 4.1: Install the software

You must have the following software components in order to start developing Android applications for your device:

If you already have Android Studio 2.0 or later in your computer, you can skip the first two installation steps.

1. Java SE Development Kit 8 (JDK 8)

Before you set up Android Studio, be sure you have installed JDK 8 or later. The Java Runtime Environment (JRE) alone is not sufficient.

For Linux users:

We recommend the Java OpenJDK-8 package. Depending on your distribution, you can install this package in two ways:

  • For Debian and Ubuntu distributions, issue this command:

    $ sudo apt-get install openjdk-8-jdk
  • For Fedora, Oracle Linux and Red Hat Enterprise Linux, issue this command:

    $ su -c "yum install java-1.8.0-openjdk-devel"

For Windows users:

  1. Check if you already have JDK 8 or later installed on your computer. If you do, you can skip this step.

    1. Open a terminal and type the following:

      ~> javac -version
    2. The version should be 8 or later. Java SE version strings have the form:

      • 1.x

      • 1.x.0

      • 1.x.0_u

        In these examples, x is the product version number and u is the update version number. For example, an installed JDK update 181 (JDK 8u181) returns:

        ~> javac -version
        javac version "1.8.0_181"
  2. If the JDK is not installed or the version is not 8 or later:

    1. Download the Java SE Development Kit 8 at www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

    2. Once the download is complete, run the executable file and follow the on-screen instructions to finish the installation process.

2. Android Studio

Android Studio provides everything you need to start developing apps for Android.

To download and install Android Studio on your computer:

  1. Download the latest Android Studio at http://developer.android.com/sdk/index.html.

  2. Follow the steps for installing Android Studio at https://developer.android.com/sdk/installing/index.html?pkg=studio.

Digi Embedded for Android has been validated with Android Studio 3.2.1, although newer versions should also work. You can download this version from https://developer.android.com/studio/archive.

3. Digi Extensions for Android Studio

To download and install the Digi Extensions on your Android Studio:

  1. Open Android Studio.

  2. Open the Android Studio Settings dialog by doing one of the following: 

    1. Select Configure > Settings on the Welcome screen.

      Dialog Settings Welcome

    2. Select File > Settings from the menu.

      Dialog Setting Menu

  3. Select Plugins from the tree on the left of the Settings dialog.

    You can also access the Plugins dialog from the Welcome screen. Click Configure on the Quick Start panel and then click Plugins.
  4. Click Browse repositories at the bottom of the page.

  5. In the Browse Repositories dialog, select Digi Extensions for Android Studio from the list on the left. You can use the search box to look for the plugin. Dialog Browse Repositories

  6. Click Install on the right panel.

  7. A dialog is displayed asking whether you would like to download and install the plugin Digi Extensions for Android Studio. Click Yes.

    A dialog displays the progress of the download process.

  8. Once the download process finishes, click Close in the Browse Repositories dialog.

  9. Click OK to close the Plugins dialog.

  10. When a message appears asking you to restart, click Restart to activate the plugin.

4. SDK Add-on

You are now ready to start developing Android applications. The Get started section provides an initial tutorial, while the Application development section gives you everything you need to start using the Digi APIX for Android to create more advanced apps.

  1. On the Android Studio Welcome screen, click Configure on the Quick Start panel and then click SDK Manager. The SDK Manager dialog opens.

    SDK manager

  2. Select the SDK Update Sites tab and click the + button at the right to add a new add-on site. User Defined Sites

  3. Enter a name for the new add-on site and use the following URL: http://ftp1.digi.com/support/android/sdk_addon/8.0/addon.xml Add update site

  4. Click OK and go back to SDK Platforms tab.

  5. Check Show Package Details to expand and list all the available Android packages for each version. A new package named Digi SDK Add-On for Embedded appears under Android 8.0 (Oreo). Digi SDK Add-On for Embedded

  6. Check the new package and click Apply.

    Make sure you have also checked Android SDK Platform 26 under Android 8.0 (Oreo) as it is required to build applications for the Android target platform.
  7. A confirmation dialog appears listing the packages that will be installed. Click OK.

  8. Accept the License Agreement and click Install.

  9. Once installation is complete, click Finish and close the SDK Manager.

  10. Restart Android Studio.

You are now ready to develop Android applications using the Digi APIX for Android.

5. Google USB driver

You need the Google USB Driver for Windows if you want to perform adb (Android Debug Bridge) debugging with your device.

  1. Download the Google USB driver at http://developer.android.com/sdk/win-usb.html.

  2. Once you have downloaded the USB driver, perform the following instructions to install it, based on your Windows version:

Windows 7 or later

To install the Google USB driver on Windows 7 or later for the first time:

  1. Unzip the downloaded file.

  2. Connect your Android-powered device to your computer’s USB port.

  3. Right-click on Computer from your desktop or Windows Explorer, and select Manage.

  4. Select Device Manager in the left pane of the Computer Management window.

  5. Locate and expand Other device in the right pane.

  6. Right-click the device name and select Update Driver Software to launch the Update Driver Software wizard.

  7. Select Browse my computer for driver software and click Next.

  8. Click Browse and locate the USB driver folder, called usb_driver, which appears after you decompress the downloaded file.

  9. Click Next to install the driver.

Windows Vista

To install the Google USB driver on Windows Vista for the first time:

  1. Unzip the downloaded file.

  2. Connect your Android-powered device to your computer’s USB port. Windows detects the device and launches the Found New Hardware wizard.

  3. Select Locate and install driver software.

  4. Select Don’t search online.

  5. Select I don’t have the disk. Show me other options.

  6. Select Browse my computer for driver software.

  7. Click Browse and locate the USB driver folder, called usb_driver, which appears after you decompress the downloaded file.

  8. Click Next. Vista may prompt you to confirm the privilege elevation required for driver installation. Confirm it.

  9. When Vista asks if you’d like to install the Google ADB Interface device, click Install to install the driver.

Step 4.2: Create the Android application

  1. Open Android Studio.

  2. Open the Import Digi Sample wizard by doing one of the following:

    • Select Import a Digi Android code sample on the Welcome screen. Import a Digi Code Sample

    • Select File > New > Import Digi Sample from the menu. Import sample menu

  3. On the Browse Samples page of the wizard, select the Getting Started Sample Application under Digi samples. Then click Next.Import Sample Wizard Step 1

  4. In the Project location field of the Sample Setup page of the wizard, specify the path where you want to download the sources of the application. Import Sample Wizard Step 2

  5. Click Finish to create the sample application. A new Android Studio window opens with the Getting Started Sample Application project.

    Android Studio will likely recommend that you update the Android Gradle plugin when you import an example. Development on the Android Gradle plugin is ongoing, but Digi samples are configured with a specific Gradle version.

    Update gradle plugin

    Click Update and Android Studio performs the update.

Step 4.3: Launch the Android application

Once you have created the project, you can launch it in your Android device:

  1. Connect the device to the development computer using a micro USB cable. Use the USB OTG connector of the device for this purpose.

  2. Ensure the device has developer and debugging options enabled. See Enable developer options and debugging for more information.

    For Linux users: In order to allow Android Studio to correctly transfer and install applications in the device, the USB connection mode must be set to Transfer files. To do so follow these steps:

    1. Open the Settings app.

    2. Choose Connected devices and then USB.

    3. Select Transfer files in the popup dialog.

  3. Select Run > Run 'app'.

  4. Select your device from the Device Chooser dialog and click OK.

    If your device appears as Unauthorized in the Device Chooser dialog, go to your Android device. A dialog shows up on your device, presenting an RSA key for your computer and asking for confirmation to accept the connection.

    Select Always allow from this computer and click OK.

    After accepting your computer RSA key, the device state changes to Online in the Device Chooser dialog.

    Device Chooser Dialog

    The application automatically transfers and launches in the Android device through the USB connection. The progress of the launch process is displayed in the Run view: Run View

  5. You can review the adb and device log messages from the logcat tab: logcat tab

Step 4.4: Test the Android application

You can test the Getting Started Sample application in the Android device by blinking the User LED on and off to configure its period.

image

You have successfully created and executed an Android application in your device. As you can see, the process is the same as with any other standard Android device.

Now you can develop more applications with Android Studio using Digi APIs to access the hardware interfaces available in your device, such as the SPI, I2C, ADC, and CAN.

To meet all your project requirements, Digi also lets you customize Android to create your own firmware images from the source code.