Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

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

public class Main {
    private static final String DELIMITER = "_";

    public static String getDeviceId(Context ctx) {
        StringBuilder sbuff = new StringBuilder();
        TelephonyManager telephonyManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);

        /*
         * getDeviceId() function Returns the unique device ID.
         * for example,the IMEI for GSM and the MEID or ESN for CDMA phones.
         */
        String imeistring = telephonyManager.getDeviceId();
        sbuff.append(imeistring + DELIMITER);

        /*
         * getSubscriberId() function Returns the unique subscriber ID,
         * for example, the IMSI for a GSM phone.
         */
        String imsistring = telephonyManager.getSubscriberId();
        sbuff.append(imsistring + DELIMITER);

        /*
         * Settings.Secure.ANDROID_ID returns the unique DeviceID
         * Works for Android 2.2 and above
         */
        String androidId = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID);
        sbuff.append(androidId);
        //Log.d("deep link device id", sbuff.toString()+"");
        return (sbuff.toString());
    }
}