Getting Device Info From MSI Android Devices
The good old ways!
On Symbol/MSI Windows Mobile devices, we where providing some APIs in the EMDK to get additional informations. Looking into the Resource Coordinator is possible to find APIs like:
- RCM_GetESN() - retrieves the device electronic serial number
- RCM_GetUniqueUnitId() - retrieves the unique unit identification number
- RCM_GetVersion() - retrieves version information
- etc…
…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.
Then we can do some housekeeping deleting the unnecessary main.xml menu resource:
We can then start the two main changes: - Setting up the Activity Layout - Updating the Activity onCreate method to retrieve the device data
Here's the code:
This together with the string.xml containing the referenced string:
Get Device Info Device ESN: Build Number: Device:
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:
- Build.DEVICE = The name of the industrial design
- Build.SERIAL = A hardware serial number, if available
- Build.ID = changelist number
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:
Running this application on an MC40 with Jelly Bean you get:
While the TC55 is always a bit different :-)
Hope you may find this useful. Send me an email if you'd like to see any particular topic on this blog.
Pietro Francesco Maggi