Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * (c) Winterwell Associates Ltd, used under MIT License. This file is background IP.
 */

import java.util.Random;

import android.content.Context;

import android.os.Build;
import android.telephony.TelephonyManager;

public class Main {
    private static final Random rnd = new Random();

    public static String getDeviceId(Context context) {
        try {
            TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            String szImei = TelephonyMgr.getDeviceId(); // Requires READ_PHONE_STATE
            return szImei;
        } catch (Exception e) {
            // Oh well
        }
        try {
            String m_szDevIDShort = "35" + //we make this look like a valid IMEI
                    Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10
                    + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10
                    + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10
                    + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10
                    + Build.USER.length() % 10; //13 digits
            return m_szDevIDShort;
        } catch (Exception e) {
            // Oh well
        }
        return "tempid" + getRandom().nextInt();
    }

    public static Random getRandom() {
        return rnd;
    }
}