Java tutorial
//package com.java2s; import android.content.Context; import android.os.Build; import android.provider.Settings; import android.telephony.TelephonyManager; import org.json.JSONException; import org.json.JSONObject; public class Main { /** * Get unique device info. * * @param context application context. * @return returns a json object of the device, manufacturer, build version, and a unique id. */ public static JSONObject getDeviceInfo(Context context) { JSONObject deviceInfo = new JSONObject(); try { deviceInfo.put("device", Build.MODEL); deviceInfo.put("manufacturer", Build.MANUFACTURER); deviceInfo.put("android", android.os.Build.VERSION.SDK); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String tmDevice = tm.getDeviceId(); String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); String serial = null; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) serial = Build.SERIAL; if (androidId != null) deviceInfo.put("uid", androidId); else if (serial != null) deviceInfo.put("uid", serial); else if (tmDevice != null) deviceInfo.put("uid", tmDevice); deviceInfo.put("carrier", tm.getNetworkOperatorName()); } catch (JSONException e) { e.printStackTrace(); } return deviceInfo; } }