Garbage Collector

Tales from an old nibble


Getting device info from MSI Android devices

Table of Contents

The information in this article is obsolete.
Please refer to the Android documentation for updates on this topic

The good old ways! #

On Symbol/MSI Windows Mobile devices, we where providing some APIs in the EMDK to get additional information. Looking into the Resource Coordinator is possible to find APIs like:

…and we don’t have anything like this in the Android EMDK. WHY?

Simply because the functionality is already included in the standard Android SDK.

Let’s see how to get this is data on an MSI device with the Android OS.

The fabulous new way! #

You can find the completed project in this repository on my github account, I’m using Windows 7 and Eclipse+ADT, but you can follow these steps with Android Studio quite nicely.

Create a new Project #

Create a new Android project, nothing fancy here, it’s just a standard app with a single Blank Activity. You can follow these images as a guideline. Your interface may vary as Google updates the Android wizard quite often.

Android New Project Wizard - page 1. Android New Project Wizard - page 1

Android New Project Wizard - page 2. Android New Project Wizard - page 2

Android New Project Wizard - page 3. Android New Project Wizard - page 3

Android New Project Wizard - page 4. Android New Project Wizard - page 4

Android New Project Wizard - page 5. Android New Project Wizard - page 5

Then we can do some housekeeping deleting the unnecessary main.xml menu resource:

Delete unnecessary menu. Delete unnecessary menu

We can then start the two main changes:

Main Activity Layout. Main Activity Layout

Here’s the code:

<?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"
    >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/device_name"
        />
    <TextView
        android:id="@+id/device_type"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:textSize="18sp"
        style="?android:listSeparatorTextViewStyle"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/electronic_serial_number"
        />
    <TextView
        android:id="@+id/device_esn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:textSize="18sp"
        style="?android:listSeparatorTextViewStyle"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/build_number"
        />
    <TextView
        android:id="@+id/build_number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:textSize="18sp"
        style="?android:listSeparatorTextViewStyle"
        />
</LinearLayout>

This together with the string.xml containing the referenced string:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Get Device Info</string>
    <string name="electronic_serial_number">Device ESN:</string>
    <string name="build_number">Build Number:</string>
    <string name="device_name">Device:</string>

</resources>

Then the simple Activity java code to collect the information is:

package com.pietromaggi.sample.getdeviceinfo;

import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.widget.TextView;


public class MainActivity extends ActionBarActivity {
    TextView DeviceNameTextView;
    TextView ESNTextView;
    TextView BuildNumberTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        DeviceNameTextView = (TextView)findViewById(R.id.device_type);
        DeviceNameTextView.setText(Build.DEVICE);

        ESNTextView = (TextView)findViewById(R.id.device_esn);
        ESNTextView.setText(Build.SERIAL);

        BuildNumberTextView = (TextView)findViewById(R.id.build_number);
        BuildNumberTextView.setText(Build.ID);
    }
}

Where’s the tricks? #

There’s really no trick, Android SDK provide this information, and more using these constants:

Obviously, it’s the OEM building the device that put together the plumbing to link the correct information. Your mileage may vary on different devices.

Running this application on an ET1 with Jelly Bean you get:

ET1 Screenshot. ET1 Screenshot

Running this application on an MC40 with Jelly Bean you get:

MC40 Screenshot. MC40 Screenshot

While the TC55 is always a bit different :-)

TC55 Screenshot. TC55 Screenshot

Hope you may find this useful. Send me an email if you’d like to see any particular topic on this blog.