get System Serial Number - Android android.os

Android examples for android.os:SystemProperties

Description

get System Serial Number

Demo Code


//package com.java2s;

import java.lang.reflect.Method;

public class Main {
    public static String getSerialNumber() {
        String serialNumber = "";

        try {/*from w w w.  ja  v a2s .c  o  m*/
            Class<?> c = Class.forName("android.os.SystemProperties");
            Method get = c.getMethod("get", String.class);
            serialNumber = (String) get.invoke(c, "ro.serialno");

            if (serialNumber.equals("")) {
                serialNumber = "?";
            }
        } catch (Exception e) {
            if (serialNumber.equals("")) {
                serialNumber = "?";
            }
        }

        return serialNumber;
    }
}

Related Tutorials