Search This Blog

18 June 2010

Phone ID and Other Useful Tidbits

Let's start with a basic project:

F:\work> mvn archetype:generate -DarchetypeCatalog=http://kallisti.eoti.org:8081/content/repositories/snapshots/archetype-catalog.xml
2: http://kallisti.eoti.org:8081/content/repositories/snapshots/archetype-catalog.xml -> galatea-archetype (null)
groupId: org.eoti.android.phone
artifactId: PhoneIDTest
version: 1.0-SNAPSHOT
package: org.eoti.android.phone


F:\work> cd PhoneIDTest
F:\work\PhoneIDTest> mvn clean install

Add this to your AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Add this convenience method to your PhoneIDTestActivity:
    private void showMessage(String msg)
    {
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }

Insert this into the end of your onCreate method:
        TelephonyManager mgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        switch(mgr.getPhoneType())
        {
            case TelephonyManager.PHONE_TYPE_CDMA:
                showMessage("CDMA");
                break;
            case TelephonyManager.PHONE_TYPE_GSM:
                showMessage("GSM");
                break;
            case TelephonyManager.PHONE_TYPE_NONE:
                showMessage("NONE");
                break;
            default:
                showMessage("Unknown phone type");
        }

        showMessage("Device ID: " + mgr.getDeviceId());
        showMessage("Version: " + mgr.getDeviceSoftwareVersion());
        showMessage("Number: " + mgr.getLine1Number());
        showMessage("Country: " + mgr.getNetworkOperatorName());
        showMessage("Sim Serial#: " + mgr.getSimSerialNumber());
        showMessage("Subscriber ID: " + mgr.getSubscriberId());
        showMessage("Operator: " + mgr.getSimOperatorName());
       
Redeploy (mvn clean install) and run the app.

No comments:

Post a Comment