Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.app.Activity;

import android.content.Context;

import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;

public class Main {
    /***
     * getIMEI : read the IMEI number of device The IMEI (14 decimal digits plus
     * a check digit) or IMEISV (16 digits) includes information on the origin,
     * model, and serial number of the device. The structure of the IMEI/SV are
     * specified in 3GPP TS 23.003
     * 
     * @param activity
     * @return 16 digit IMEI number of device ( padded with zeros)
     */
    public static String getIMEI(Activity activity) {
        try {
            TelephonyManager telephonyManager = (TelephonyManager) activity
                    .getSystemService(Context.TELEPHONY_SERVICE);
            String imei = telephonyManager.getDeviceId();
            if (imei == null)
                imei = Secure.getString(activity.getContentResolver(), Secure.ANDROID_ID);
            return imei;
        } catch (Exception e) {
        }
        return "EEEE-EEEE-EEEE-E";
    }
}