Introduction
If you haven't noticed already, the MaaXBoard Mini supports Android 9 out of box! One thing that developers are probably wondering is how do I go through the process of actually developing my own application and deploying it on the MaaXBoard Mini? Well look no further, I have gone through the process of documenting everything required to get you started with your application development!
Version
Date | Version | Revision |
---|---|---|
26 October 20 | 01 | Initial Release |
- Required Hardware
- Required Development Software
- Download and Install Android Studio
- Do a quick google search and it will take you right there
- Download and install adb platform tools
- Do a quick google search of "adb platform tools" and you should find them fairly easy. Install them for the OS you are using on your PC.
- Download and Install Android Studio
- SD Card Setup
- Place your 16GB microSD Card into your PC
- Go to http://avnet.me/maaxboard-mini -> Reference Designs tab -> MaaXBoard Mini -> Anrdoid 9 Out of Box Image.
- Download the Android 9 Out of Box Image for the MaaXBoard Mini
- Use a flash program such as Win32DiskImager or Etcher to flash the Android 9 Out of Box Image .img image onto the 16GB microSD Card
- Hardware Setup
- Connect the MaaXBoard Mini with the MaaXBoard 7in LPC panel.
- Connect the ribbon cable from the display to J7 on the MaaXBoard Mini
- Place the microSD card you just flashed with Android 9.0 out of box image into the microSD slot (J9) on the MaaXBoard Mini
- Connect the USB Type A plug to Type A plug cable into USB hub J2 on the MaaXBoard Mini bottom port. Plug the other end of the cable into your PC
- Plug the USB Type C Power Supply into J11 USB Type C socket on the MaaXBoard Mini. Plug the other end into the wall.
- Note: if you are using a different USB Type C cable plugged into your PC, you will encounter power issues when working with the LCD panel. Please us a 3A/5V power supply
- The board should now power on
- Connect the MaaXBoard Mini with the MaaXBoard 7in LPC panel.
- Verify your adb platform tools setup.
- Open up command line prompt
- Traverse in the command line prompt to the adb tools you setup. Go to the platform-tools directory
- In the command line type adb devices
- Type adb shell and a terminal shell will open to your MaaXBoard Mini
- You can now run shell commands directly on the MaaXBoard Mini. Lets control some leds!
- type su - This will give you root privlidges
- type echo 0 | tee /sys/class/leds/usr_led/brightness - This will turn an led off
- type - This will turn the other led off
- type echo 1 | tee /sys/class/leds/usr_led/brightness - This will turn an led on
- type echo 1 | tee /sys/class/leds/sys_led/brightness - This will turn the other led
- Type Exit to exit the shell terminal
- You have verified your adb platform tools setup.
- Open Android Studio and explore the environment
- Create a new project File -> New -> New Project
- Select Empty Application -> Next
- Make sure the Lanugage is set to Jave and select Finish
- You have now created your first project! Lets dig into the layout design and java application portion of creating an app.
- Go to Android -> app -> res -> layout -> activity_main.xml
- This is where you design the layout of your app. You can drag and drop multiple buttons/tesxt/widgets etc into your application
- If you go to the Code portion you will see the .xml code that was created when you dropped your button. You will notice here is where we can rename the button id that our java application will call when a event occurs.
- Now go to Android -> app -> java -> com.example.myapplication -> Main activity
- Here is where we will write the main java portion of our example application.
- Example Addition Application
- I have gone through the process of creating a simple addition application we will run on the MaaXBoard Mini.
- Open the activity_main.xml, go to the code section. Copy and paste below. You will see how this layout will look on the MaaXBoard Mini by going back to design.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/fstTxt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="100dp" android:layout_marginTop="150dp" android:text="First Number" /> <EditText android:id="@+id/firstNum" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="100dp" android:ems="10" /> <TextView android:id="@+id/secTxt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Second Number" android:layout_marginLeft="100dp" /> <EditText android:id="@+id/secondNum" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="100dp" android:ems="10" /> <Button android:id="@+id/addBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="100dp" android:text="Add" /> </LinearLayout>
- Open the MainActivity File again, Copy and past the below application code. This will add two numbers we enter together.
package com.example.myapplication; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; import android.app.Activity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final EditText firstNum = (EditText)findViewById(R.id.firstNum); final EditText secNum = (EditText)findViewById(R.id.secondNum); Button btnAdd = (Button)findViewById(R.id.addBtn); btnAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(firstNum.getText().toString().isEmpty() || secNum.getText().toString().isEmpty()) { Toast.makeText(getApplicationContext(), "Please fill all the fields", Toast.LENGTH_SHORT).show(); } else { int num1 = Integer.parseInt(firstNum.getText().toString()); int num2 = Integer.parseInt(secNum.getText().toString()); Toast.makeText(getApplicationContext(), "SUM = " + (num1 + num2), Toast.LENGTH_SHORT).show(); } } }); } }
- Our example application is now created
- Run the application on the MaaXBoard Mini
- Make sure in Android Studio the target selected is freescale EVK_8MM
- If you don't see freescale EVK_8MM make sure your MaaXBoard Mini is powered up and you can communicate with it using the adb tools.
- In the Android Studio menu select Run -> Run...
- You will see this output on your MaaXBoard Mini
- Make sure in Android Studio the target selected is freescale EVK_8MM
- Deploying your end application
- Now that we have designed a basic application, how do we deploy this? From my experience an easy way to share the desing file is by builiding it as an apk
- In the Android Studio go Build -> Build Bundle(s) / APK(s) -> Build APK(s)
- In the bottom right you will see when the APK has been build, select locate to open the directory
- You will see the APK has a default name, rename it to whatever you wish.
- Now that we have geneated the APK, i'll quickly show you how to use the adb tools to install the application.
- Open up the command line we were working in again with the adb tools.
- type adb install path to .apk for example
- You can verify the package has been installed by typing adb shell pm list packages
- You will be given a list of installed packages, search for the one you installed!
Please let me know if you have any questions, i'm always interested in hearing about your latest designs and activities around the MaaXBoard or MaaXBoard Mini!
-Josh